Open In App

Google Interview Experience (On-Campus) 2022

Last Updated : 14 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Before we begin: ONLY DSA Questions were asked. Not a single question related to OS, DBMS, CNS, OOP, System design or even Resume was asked. So now you know what to focus on.

Round-1 (Online Coding Test, Platform: HackerEarth): All students were eligible for Round-1. (No constraints based on CPI or active backlogs)

Q1 (30 points): You are given a string S of length N consisting of digits from ‘0’ to ‘9’. You need to partition the string in ‘K’ substrings such that each substring starts with an even digit and ends with an odd digit. Each substring must be of Length at least equal to ‘M’. Determine the total number of ways in which you can partition the string into ‘K’ substrings. Give answer modulo 1e9+7.

Sample: N=9, M=2, K=3, S=’454569421′

Ans = 3 (way-1: 45 | 45 | 69421 , way-2: 4545 | 69 | 421 ,  way-3: 45 | 4569 | 421 )

Approach: can be done using DP (recussion + memoization)

Q2 (30 points): Given a n-ary tree with N nodes and each node has some value associated with it (given in the form of the array). A path is called special if it satisfies the following conditions:

  • all nodes in a path are traversed exactly once.
  •  value of starting node = value of ending node.
  • starting node is not equal to the ending node
  • values of all nodes in a path are not greater than the value of starting node. 

Count the total number of special paths in a tree. Two paths are different if they contain at least one different node.

Ans: Naive approach works. Constraints were not tight.

Verdict: Got selected for Interviews. Total 19 people were selected out of 370 in our batch.

Round-2 (Online Interview, Platform: google meet): Only one DSA Question was asked. The time allotted was 45 mins.

Q1: You are given an array where each element represents the number of floors of the building. In one operation you can remove one floor from any building. After a certain number of operations, the number of floors of all buildings must be either zero or equal to some specific non-negative number ‘K’. You have to find a minimum number of operations required and a value of K.

Sample: arr = [1,3,4,7,8,9] .  Ans: minimum operations = 11. K=7. Final array: [0,0,0,7,7,7] 

Approach: can be done using prefix-sum.

The interview was conducted on a platform called “google-interview”. The interviewer first asked me to explain my approach which I did. Then he told me to code. Now comes the tricky part, coding on “google-interview” is kinda similar to coding on Notepad. Auto indentation is off, Auto-completion is off, and Suggestions are off. This was intentionally done to check How to clean code can candidate write.

IMP TIP: Write clean code with proper indentations. Also try to declare self_explanatory variable names [ such as my_turn, next_person, etc, and not as mt, np, etc].

Round-3 (Online Interview, Platform: google meet): Only one DSA Question was asked. The time allotted was 45 mins. Followed by 15 mins of G&L round.

Q1. You are given an n-ary tree where each node can have up to n children ( i.e. 0 to n ). A frog is currently sitting at a root node. It is given that frog can jump from the current node to any of its child nodes with equal probability. The frog can stay on the current node only if the current node has zero child nodes (i.e. leaf node) otherwise frog must jump. For each node find the probability that the frog is present at that node after an infinite amount of time.

Inference: Only leaf nodes will have non-zero probability, the rest of the nodes will have zero probability.

Approach: Simple DFS. 

  • Let’s say the frog is at some arbitrary node-x which has m-children and the probability to reach node-x from the root is Px.
  • The probability to jump from node-x to any of its child nodes is 1/m. 
  • The probability of a frog reaching any of its child nodes from the root is = (Px)*(1/m) = Py.
  • For each node, we store the value of Py in our result array. And finally, we change the value of Py to zero for all non-leaf nodes in the result array.

I was able to code the above-mentioned approach on the “google-interview” platform in almost 20 mins. The interviewer was satisfied. 

Follow-up Question: Instead of a tree, assume it is a Directed acyclic graph.

Approach: Simple DFS but only on outgoing edges.

  • The probability to reach the current node-x from the root will now be equal to the sum of probabilities from all its incoming edge path.
  • we will only jump to the children node from the current node-x when we’ve traversed all the incoming edges of node-x.

The interviewer was satisfied with my approach as well as my code. It was a green flag from his side. This boosted my confidence level.

G&L Round 1: (Googliness and Leadership round): The time allotted was 15 mins.

Q. You are working on a project in a team size of 10 members where each and every member is contributing equally and to the best of their abilities. However, Team leader is taking all the credit in meetings with senior managers. What will you do in such a situation?

Verdict: 10 people were selected for Round-4 out of 19.

Round-4 (Online Interview, Platform: Google Meet): One DSA Question was asked. The time allotted was 45 mins. Followed by 15 mins of G&L Round.

Q1. Assume a cartesian coordinate system. You are given the position coordinates of a set of K routers. All routers are capable of sending and receiving signals. Out of these K routers, One router is termed as “Source” and one specific router is termed as “Destination”. You are given a Range-R. When a router sends a signal, all routers within range R will receive the signal and then they will re-transmit the signal. (Imagine this range-R as a circle of radius=R). Determine whether the “Destination” router will receive a signal transmitted by the “Sender” router.

Approach: Simple BFS

  • Start BFS from the source router
  • We calculate the shortest distance between the current router and all unvisited routers. If the shortest distance is less than R, we put the coordinates of that router inside the queue and mark those routers as visited.
  • After completion of BFS, check whether is destination router is marked as visited or not.

Again coded this solution on “google-interview”.

Follow-up question: If there are too many queries of different sources and different destinations, will it be feasible to apply BFS each and every time? What will you do in that case?

Ans: We can memoize our solution. And only apply BFS when the solution is not present in our cache.

He was satisfied with the solution and didn’t ask me to code because of time constraints.

G&L Round-2 (Googliness and Leadership): The time allowed was 15 mins.

Q. Since you are active in various extracurriculars. Did you ever take any new initiatives like organizing a new event or anything of that sort? What was people’s reaction and how you dealt with those who were opposing you??

Pro Tip: Nothing New.

  • Try to be polite and humble. Don’t use negative words.
  • Don’t try to be over smart. Give Answers to the point.

Final Verdict: Received an offer from Google. 5 people received out of 10.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads