Question bank › Trie
Dsa Trie Medium

File Extension Tracker

A file management system allows users to track the files by their extensions. You need to implement a class called `FileTracker`, which includes a method to add file names and another method to return the count of files for each extension. Implement the following methods: 1. `add_file(filename: str)`: Adds a file name to the tracker. 2. `file_count(extension: str) -> int`: Returns the number of files with the specified extension. The input consists of a mix of 'ADD filename' commands and 'COUNT extension' commands. The commands are case-sensitive. Input Format: - Each command is on a new line. The last line contains a command 'END'. Output Format: - Output the result of each 'COUNT' command on a new line, containing the count of files with the specified extension. Example: Input: ADD example.txt ADD sample.pdf COUNT txt COUNT pdf ADD another.txt COUNT txt END Output: 1 1 2

Key concepts

triefile-systemstring-manipulation

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.