Citadel phone screen

Posted
10 Jun 2025
388 reads

Summary

I had a phone screen with Citadel where I was asked to implement a Trie and its supporting functions, followed by an optimization question and a bonus question to find the longest prefix. I cleared the round.

How it went

Implement Trie and it's supporting functions -

* insert(word) - Insert a word in the trie,

  • search(word) - search if the word exists in the trie, and
  • startsWith(prefix) - search if there exist any word which starts with <prefix>.

Clarified if we are only dealing with lowercase alphabets. Yes.

I implemented
TrieNode
like below.

class TrieNode{
int val;
vector<TrieNode*> children;
};

Follow up question.
Currently, we are occupying 26 space for children. How can we optimize it ?
Suggested to use a Map instead of vector.

class TrieNode{
int val;
unordered_map<int, TrieNode*> child;
};

// int denotes 0 for 'a', 1 for 'b', or you can do char too in this case. // I chose int.


Looks good.

Bonus question.

Implement

longestPrefixWhichStartsWithPrefix(prefix) - find the longest prefix which starts with a given prefix.

prefix = abc
words = [abcdef, abcdeg] -> abcde

Cleared the round.

Questions asked (2)

  1. 01

    Implement Trie and its Supporting Functions

    Data Structures & Algorithms · Medium

    Implement Trie and it's supporting functions -

    * insert(word) - Insert a word in the trie,

    • search(word) - search if the word exists in the trie, and
    • startsWith(prefix) - search if there exist any word which starts with <prefix>.

    Clarified if we are only dealing with lowercase alphabets. Yes.
  2. 02

    Longest Prefix Which Starts With Prefix

    Data Structures & Algorithms · Medium

    Implement

    longestPrefixWhichStartsWithPrefix(prefix) - find the longest prefix which starts with a given prefix.
    

    prefix = abc
    words = [abcdef, abcdeg] -> abcde

Know someone preparing? Send it to them:WhatsAppLinkedInX

Interviewed at Citadel recently?

Write up your rounds while you still remember the questions. It helps the next person more than you would think.

Share your experience
Discussion 0

Questions for the author, or how your own interview compared.

Join the discussion

Sign in with Google to comment or ask the author a question.

No comments yet

Be the first to share your thoughts and start the discussion!