Microsoft Interview Question


Country: India
Interview Type: Phone Interview




Comment hidden because of low score. Click to expand.
10
of 10 vote

Dictionary using trie - each node as number bit, so there will be a node 2 representing "abc", Hence tree till have 9 nodes as root and so on.

- anim June 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

so far the best explanation I could find. I have written a short write up explaining your answer.

- NaMo June 30, 2013 | Flag
Comment hidden because of low score. Click to expand.
4
of 4 vote

construct dictionary using trie with augmentation.
Instead of char key's, use numbers corresponding to combination for chars.

for eg. 2 for {a,b,c} 
	     3 for {d,e,f} and so on till 9 {w,x,y,z}

so the first level would contain 9 nodes.
Consider a word "book" in dict.
It would be inserted in order - 2665.
create a linked list / priority queue of words corresponding to same number combination in the terminal node and display the words either randomly or based upon priority.

- NaMo June 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

kya mje koi ic uper waly likhy hue ka code send kr skta hai mera email id hai zainrauf71@gmail.com

- rauf January 06, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

277451366514612382623

- chetan paralkar March 31, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

4056830968

- 4056830968 March 26, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

6259

- Anonymous November 20, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class Key
{
public:
    Key()
    {
    }
    static int zero,two,three;
    static int four,five,six,seven,eight,nine;
    static int get( char ch )
    {
        if ( ( ch == 'a' ) || ( ch == 'b' ) || ( ch == 'c' ) )
        {
            return Key::two;
        }
        if ( ( ch == 'd' )  || ( ch == 'e' )  || ( ch == 'f' ) )
        {
            return Key::three;
        }
        if ( ( ch == 'g' )  || ( ch == 'h' )  || ( ch == 'i' ) )
        {
            return Key::four;
        }
        if ( ( ch == 'j' )  || ( ch == 'k' )  || ( ch == 'l' ) )
        {
            return Key::five;
        }
        if ( ( ch == 'm' )  || ( ch == 'n' )  || ( ch == 'o' ) )
        {
            
            return Key::six;
    }
    if ( ( ch == 'p' )  || ( ch == 'q' )  || ( ch == 'r' )  || (ch == 's'))
    {
        return Key::seven;
    }
    if ( ( ch == 't' )  || ( ch == 'u' )  || ( ch == 'v' ) )
    {
        return Key::eight;
    }
    if ( ( ch == 'w' )  || ( ch == 'x' )  || ( ch == 'y' )  || (ch == 'z'))
    {
        return Key::nine;
    }
    return Key::zero;
}
};
int Key::zero = 0;
int Key::two = 2;
int Key::three = 3;
int Key::four = 4;
int Key::five = 5;
int Key::six = 6;
int Key::seven = 7;
int Key::eight = 8;
int Key::nine = 9;

class T9dict
{
    vector<unordered_set<string>> _dict;
public:
    T9dict( vector<string>& words )
    {
        _dict.resize(10);
        addWords(words);
    }
    void addWords( vector<string>& words  )
    {
        for (string w: words)
        {
            if ( w.empty() )
                continue;
            
            _dict[Key::get(w[0])].insert(w);
        }
    }
    const unordered_set<string>& lookup( int key )
    {
        return _dict[Key::get(key)];
    }
};

- drolmal April 07, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More