Open In App

Google Interview Experience

Last Updated : 08 Aug, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Round 1: Was just a phone call with a local person giving me instructions and what to study for round 2.

Round 2: Google meeting interview with google docs shared screen.

The interviewer asked if I have heard about the Huffman Tree (I said no). Then he started to describe what this data structure represents by drawing a tree and the constraints

More or less like this:

                                e
                         b           z

The bytes represented in the tree are compressed, so 

e b z turns into 0 10 11.

Write a function to decode a Map parameter and return the tree represented. In other words, decode the Map.

Example map:
map: {'b: 2, 'e': 1, 'z': 2}
The map contains a key which is a char and the value of this key is the depth.
So same depths should be the children of the same root.
Example 2:
// map: {'b': 2, 'e': 2, 'f': 2', 'z': 2}
/*
      *
    *  *
   b e f z
/*

/* Constraints

* shorter paths go to left
* earlier chars in the alphabet go to the left
* All valid trees are full (all internal nodes have two children)
* values are only at leaf nodes
*/

class Node {
 Node left;
 Node right;
 char letter;  // doesn't matter for internal nodes
}
Node decodeTree(Map<Character, Integer> treeAsMap) {};

Just search for Huffman Tree and all information needed will be shown.

I couldn’t figure out an algorithm but it seems to be not that hard. I tried to start by reversing sorting the values to get the higher depths first and then start to fill the Nodes. But later I figured out that I needed a Linked List to not be concerned about the depths and was too late. The interviewer gave me many hints when he sees that I’m struggling.

Let’s keep studying and see you again in 6 months Google.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads