Google New Grad phone screen (rejected)
Anonymous User
1882

You are given a list of salaries on coseciutive days and integer K. Find two coseciutive not overlapping invervals of salaries that sum up to K and cover smalles possible amout of days. Return how much days they cover.

Example:
[1, 2, 2, 3, 2, 6, 7, 2, 1, 4, 8], K = 5
Ans: 4, (2, 3 and 1, 4 are smallest inverals and they cover 4 days, day 3 and 4 and day 9 and 10 . Note that 2, 3 and 3, 2 would not be valid anwser because it overlaps)

I wasn't given full information or examples at first, interviwer wanted that I understand the question and i am able to give him some examples with results before he gives me his examples.

My approach was dynamic programming, creating two DP arrays. One with best result (found by sliding window) coming from left and the other one with best result coming from right. Then just iterate once over those two arrays to find best result sum. Interviewer was very happy with that approach but I ran out of time while my code still had some bugs (that i see now :) ).

After that i was invited to a second phone interview.

The question started easily, I was given a interface of a serivice for logging how much time a request took. There were two methods, both taking String requestId as parameter - startRequest() and endRequest(). I have implemented it using a HashMap, added some edge case checks (like handling scenario if endRequest is executed before startRequest). After that i was asked how would i unit test such a service. Had a good converserion with interwiewer about few approaches like tracking map size or using mocked object to printing logs and verifing method invocation parameter. It was awsome till this point. Then he asked me follow up: what if we want to print requests in order they were receieved? I needed to ask few clarification questions and is should work like this:

When request A comes at time 10 and request B comes at time 20, then if request B is ended at time 30 we cannot print it because there is still not printed request before it. We should wait for A to be ended and then print both A and B (B after A ofcourse). It can get complicated if you think about more requests. Due to time pressure I kept confiusing myself and trying overcomplicated aproaches like graph / tree. At the end i came up with solition using HasMap for tracking request time, Queue for keeping order of printing and HashSet for keeping what requests have already been ended but are still waiting to be printed. The idea is: When request comes in, record it in a Map and add to Queue. When it ends update a map with time that it took and add it to Set of waiting to be printed. Then while waiting to be printed contains(Queue.peek()) keep on printing and poping / removing elements. Unfotunatly my time ended before i could finish it. Got rejected.

I have solved 294 questions on LeetCode - 176 medium, 92 easy, 26 hard and around 50 questions on hackerrank. I was also doing mock interview section on LeetCode for Google (got premium) and random question sets, finished 47 mocked interviews (mostly phone screens) with avg score 7.66 at the end. Before my interviews in about 2 weeks period i have solved around 100 questions. It was my first time doing this kind of interviews, stress and time presure is a really big factor. I feel like the second phone interview was really easy and i could ace it with no problems, but on the call my head was empty and i just kept confusing myself. Anyway i'm not losing hope, I will keep prepearing and try next time :). Best of luck to everyone.

Comments (6)