# Google Interview Experience SDE-1 (Off-Campus) 2022

**Round 1** – Resume shortlisting

**Round 2** – Recruiter call (15-20 mins phone conversation)

**Round 3 **– Phone interview (45 mins technical interview conducted on meet)

**Question asked: **https://leetcode.com/problems/time-needed-to-inform-all-employees/

A variation of this question was asked as the head node wasn’t given that is it wasn’t certain to which manager CEO will give the message and my task was to first find out which node should be the starting point and then find the total time taken to reach all employees.

Also, input was not a simple integer it was a structure containing name, employee id, and an array of employees reporting to that employee. I went ahead with graphs for solving this question, first ran a DFS to find out the head node that is the employee to which if the CEO gives the message it reaches all employees and then ran a BFS to find out the total time taken for the message to reach all employees.

**Round 4** – Onsite Interview (Conducted on meet – 15 mins GNL round, 45 mins technical)

**GNL round** – Googliness and Leadership round where behavior-based questions are asked to check if the candidate is the right fit for Google culture.

**Questions asked:**

- How many binary numbers of length n are possible?

For ex. n=2, binary numbers possible are – 00,01,10,11 similarly for any length n total number of possibilities will be 2^n

- https://www.techiedelight.com/find-n-digit-binary-strings-without-consecutive-1s

A variation of this question was asked that no two consecutive zeroes should be together.

I approached the question with recursion then optimized it with Dynamic programming and finally, the most optimized code didn’t use any extra space and had O(n) time complexity. - https://math.stackexchange.com/questions/1322767/find-a-recurrence-relation-for-the-number-of-ternary-strings-of-length-n-that-do

A variation of this question was asked that no two consecutive zeroes should be together and three consecutive 1’s. My approach was similar to the above question first start with recursion than dynamic programming and the final solution was O(n) time complexity with no extra space used

**Round 5 (Onsite interview) **

*Conducted on meet – 15 mins GNL round, 45 mins technical*

**Question asked – **Given input equations, output true or false

For ex. {a>b, b>c ,c>d, d>a} is this input true or false?

Here the input is contradicting so the output will be false. My approach was considering all variables as nodes of the graph and then drawing an edge from vertex u to v if u>v and output will be false if a cycle is present in the graph.

Topological sort of DFS can be used to detect cycles in directed graphs.

**Round 6 (Onsite interview):**

*Conducted on Meet – 15 mins GNL round 45 mins technical*

**Questions asked**

- Given an input string s of characters, return index where s[i] < s[i-1]

For ex. - "De-Hi&yaR2" Output - 7

**Explanation: **Hyphen, ampersand and other characters which are not alphabets don’t have to be considered for alphabetical order of string and capital or small letters don’t matter as e>d and also e>D so my approach while solving the question was to convert all letters to smaller case and then compare them and ignore other characters if encountered.

- An array is given where arr[i] holds the frequency of number present in arr[i+1] and we are supposed to implement next() and hasNext() method such that until the frequency of all numbers is 0 hasNext() returns true and next() returns the first number while traversing array which has non zero frequency.

For ex. [0,5,1,2,3,0,5,2]

Output – If next() is called it will return 2 as the frequency of 2 is 1 and the value before it which was 5 has frequency 0 so that’s not returned, now the frequency of 2 will become 0 as the next() pops the value out.

Now when next() is called again it will output 0 as the frequency of 0 is 3 and now it will become 2. The next() can be called multiple times so on till hasNext() doesn’t return false.