Google L4 Interview experience[ giving back to community]
Phone Screen
- number of 3 * 3 submatrics, which have maximum number of one's. given current matrics is of size n * m (where n >=3 and m >= 3). (Dp solution i gave them)
- some meduim hashing question, i don't remeber exactly the question. but it was medium level question.
From mine side i was able to solve both and interviewer was happy.
OnSite 1
- First he asked me what interesting work i have done till now.
- I was given a question during an interview where some strings were associated with points, like:
[
["cat.animal", 5],
["animal", 10],
["lion.animal", 15],
["tiger.cat.animal", 20]
]Each string contributes its points to itself and any of its parent nodes. The goal was to return only the leaf strings (i.e., strings that don't have any children) along with their total aggregated points.
Below is expected output
[
["lion.animal", 25], # 15 (self) + 10 (animal)
["tiger.cat.animal", 35] # 20 (self) + 10 (animal) + cat.animal(5)
]Only two leaf nodes exist in this case: lion.animal and tiger.cat.animal.
At first, I found the problem a bit confusing. But once it made sense, I quickly realized that a Trie would be the most efficient way to solve it.
I built a reverse Trie (from right to left), inserted the strings, and then used post-order traversal to calculate the total score for each node and find the leaf nodes.
After the initial analysis, I coded the solution in about 5 minutes. The interviewer seemed quite pleased, but still don't know what happens next
Mine assumption is Hire for this round
OnSite 2
1st question
arr = [1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1]
Goal:
Find the maximum continuous window where all elements are 0.
My Approach:
I used a variation of Kadane’s algorithm (maximum subarray sum) where I treated 0 as +1 and 1 as -∞ or reset the count whenever I encountered 1. This allowed me to find the longest contiguous segment of zeroes.
I solved this part within the first 5 minutes, and the interviewer was happy with the quick and efficient approach.
Follow-up
Given that we can flip at most K 1s to 0s, find the longest window that becomes all zeros after flipping.
⏱️ My Solutions:
First Attempt (O(N) Time & O(N) Space):
I used a sliding window with a queue (or array) to keep track of the indices of 1s. This allowed me to efficiently manage flips and window boundaries.
Optimized Version (O(N) Time & O(1) Space):
Then I proposed and implemented a more optimal solution using a pure sliding window with two pointers and a counter for the number of flips used.
No extra space was needed beyond variables to track state, making it both time and space efficient
2nd question
given two city A and B, where you need to collect profit and cost of switching between the cities was given as negative like -5. find the maximum profit you can collect given you can start from any city and switch as many time you want.
A = [2, 3, 4, 5 ,6]
B = [4, 3, 6, 5 ,8]
switch Cost = -5
I coded recusive method and added dp to it.
The interviewer seemed quite pleased, but still don't know what happens next
Mine assumption is Strong Hire for this round
OnSite 3
It was some string dp question which can be solved via map and trie.
i solved it and coded it, interview was completed before time.
The interviewer seemed quite pleased, but still don't know what happens next
Mine assumption is Strong Hire for this round
OnSite 4
some behaviour question, some of them i practised from chat gpt.
Waiting for recruiter call, finger crossed.


