Google Interview Question for Technical Support Engineers

Country: United States
Interview Type: Phone Interview

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

Use Topological sort

- guilhebl May 02, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

Here's a DFS approach with time O(N^2) and space O(N^2)

1) define a class Task { public: string name; bool finished; }
2) create auxillary vector<Task> for each task
for each task in auxillary array:
  push task on stack<Task&>
  if has dependency, push them on stack
    - Note: have to check for circular dependency and can have up to N-1 dependency
                so space can grow to O(N^2) in worst case
while stack not empty:
  pop top
  if Task.finished == false:
    Task.finished = true

- quangvuwpi May 10, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

Consider this as a directed graph and traverse the graph using Breadth First/Depth First. I prefer Breadth first.
- While traversing, create a dictionary to store the count of adjacent vertices to each vertex
adj(a) = 2
adj(b) = 2
adj(c) = 0
adj(d) = 1
- Set prevNode = null
- Get the nodes with minimum value in dictionary and set that as start node -- node c
- Choose the one that includes prevNode or pick one if prevNode == null
- Store it in a list
- Keep on looping and you will get the order
- Print the list

- GeekLion May 14, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

Its simple,do a topological sorting of the vertices

- Anonymous May 18, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

#include <iostream>
#include <map>
using namespace std;

void insertTask(map<char,int>& m, char lowTask, char highTask){
    m[highTask] += m[lowTask]+1;


map<int,char> toRankedMap(map<char,int> m){
    map<int,char> rankedMap;
    for(auto it : m){
        rankedMap[it.second] = it.first;
    return rankedMap;

int main()
    map<char,int> tempMap;

    insertTask(tempMap,'A','B');    //A <- B
    insertTask(tempMap,'A','C');    //A <- C

    insertTask(tempMap,'B','C');    //B <- C
    insertTask(tempMap,'B','D');    //B <- D

    insertTask(tempMap, 'D', 'C');  //D <- C

    auto rankedMap = toRankedMap(tempMap);

    for(map<int,char>::reverse_iterator rit = rankedMap.rbegin(); rit != rankedMap.rend(); ++rit){
        cout << rit->second << " < ";

    return 0;


C < D < B < A <

Process returned 0 (0x0) execution time : 0.015 s
Press any key to continue.

- Gabriel Feyer May 19, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

The way I came up with, you invert the vertices of the graph, and then do a depth first search. I used integers instead of letters, but the point is the same. This is just a dfs with tracking the path, so it should compute in O(log(V +E))

class Graph:
    def __init__(self, V):
        self.V = V
        self.graph = defaultdict(list)
        self.invgraph = defaultdict(list)

    def addEdgeDirected(self, start, end):

	def nonRecDFSInv(self, start):
        visited = [False for _ in range(self.V)]
        stack = []

        path = []

        while stack:
            current = stack.pop()
            if not visited[current]:
                visited[current] = True

            for neighbor in self.invgraph[current]:
                if not visited[neighbor]:

        return path
g = Graph(4)


[2, 3, 1, 0]

- anon September 08, 2022 | Flag Reply

Add a Comment

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


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


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