Google

  www.google.com
Work in HR? Unlock Free Profile

Google Software Engineer Interview Question

I interviewed in Los Angeles, CA and was asked:
"First Person: Simply high level questions about how to achieve certain things. For example: 1) How would you write a pancake sort routine 2) You have a network of friends (linked in friends, facebook friends, etc). How would you keep track of all the people you are connected to. 3) What is the run time of the A* search (only because I mentioned it somewhere along the line). Second person: 1) Write code to find duplicates in a linked list 2) How would you synchronize a linked list across multiple computers. If nodes are added/removed to a linked list on one computer, all others must reflect this change. Concurrancy must be accounted for"
Add Tags [?]
Answer

Part of a Software Engineer Interview Review - one of 3,047 Google Interview Reviews

Answers & Comments

0
of 1
vote
(duplicates in a linked list)

public static ArrayList<String> dups(LL l)
{
    ArrayList<String> dups = new ArrayList<String>();
    Hashtable<String, Integer> h = new Hashtable<String, Integer>();
    while (l != null)
    {
        Integer count = h.get(l.v);
        if (null == count)
        {
            h.set(l.v, 1);
        }
        else if (count.intValue() == 1)
        {
            h.set(l.v, 2);
            dups.add(l.v);
        }
        l = l.next;
    }
    return dups;
}
- Rahul on May 4, 2013

To comment on this question, Sign In with Facebook or Sign Up

Tags are like keywords that help categorize interview questions that have something in common.