You are using an outdated browser. Please update your browser for a better user experience.

Telephone Question


First, you will perform introductions and exchange greetings. Then you may get asked a question to gauge your knowledge of the company or of a specific product. For example:

  • What is your favorite Google product? What would you do to improve it?

Usually, within 10-15 minutes you are asked a technical question to gauge your problem solving abilities. Here is a question that has been asked for an over the phone coding interview at Google:

Write a Java function, printTree(), which prints a given tree to stdout. Details:

  • The argument of printTree is a stream of Relations: pairs of "parent -> child" relationships.
  • Each string found anywhere in the input represents a unique node.
  • Each parent can have many children.
  • The input list may contain Relations in arny order, although: the order in which the pairs appear in the input list determines the node's order with respect to its siblings.

Example input:

List<relation> input = new ArrayList();

input.add(new Relation("animal", "mammal"));
input.add(new Relation("animal", "bird"));
input.add(new Relation("lifeform", "animal"));
input.add(new Relation("cat", "lion"));
input.add(new Relation("mammal", "cat"));
input.add(new Relation("animal", "fish"));


Expected output:

1: lifeform
2:   animal
3:     mammal
4:       cat
5:         lion
6:     bird
7:     fish

Here is the base code to start with:

public class TreePrinter {

    public static void printTree(List<relation> rs) {
       //your code   


public static class Relation {
    String parent;
    String child;
    public Relation(String p, String c) { //constructor initialization
        this.parent = p;
        this.child = c;

The most important of this step is to communicate your thought process. The interviewer wants to know how you approach solving a problem.