Google Interview L4 -> L3 -> L4 -> L3

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2025-08-06Added By Anonymous
Source: Link

Company: Google
Role: L3, L4
Interview Stage: Onsite
Location: unknown
Year: unknown

Original Post Content:

Don't forget to upvote :)

So, I started the process at L4..

Screening Round:
Find the number of steps in the collatz sequence. What is collatz sequence:
if n is odd make it 3*n + 1
if n is even, make it n/2
find the number of steps before it reaches one

Started off with basic implementation, part two was implementing it as a string writing detailed classed, objects etc.

Feedback: Code not Modular enough
Verdict: Lean Hire

Recruiter told me, feedback is not strong enough and he would recommened me to give L3 interviews so that I have a chance of making it into Google and if those go too good, then I can interview for L4.

L3 round 1:
You have a fence consisting of n vertical planks placed side by side. Each plank has a certain height (given as an array of integers). You need to paint the entire fence.

You have two ways to paint:

  • Horizontal Stroke – In one stroke, you can choose a continuous segment of planks (from index l to r) and paint 1 unit of height across all those planks in that segment.
  • Vertical Stroke – In one stroke, you can paint the entire height of a single plank (from bottom to top) regardless of how tall it is.

Your task: Find the minimum number of strokes needed to paint the entire fence.

Heights = [1, 1, 1]
Option 1: Use one horizontal stroke across all planks (paint height 1 for all).
Minimum strokes = 1

Heights = [3, 1, 3]
Pure vertical → 3 strokes

Horizontal:
First horizontal stroke across all → [2, 0, 2]
Second horizontal stroke for first and last plank → [1, 0, 2]
Third horizontal stroke for first and last plank → [0, 0, 2]
Then do a vertical stroke (for example)→ [0, 0, 0]
→ total = 4 strokes (more than vertical)

Minimum strokes = 3

Heights = [4, 1, 3, 2]
Best approach (mixing horizontal & vertical):
Horizontal stroke across all planks at height 1 → [3, 0, 2, 1]
Vertical stroke on plank 2 → [3, 0, 0, 1]
Horizontal stroke on planks 0 and 3 → [2, 0, 0, 0]
Vertical stroke on plank 0 → [0, 0, 0, 0]
Total = 4 strokes

My solution:
I did a recursive solution, assigning min strokes as all vertical strokes. and then trying to divide along the minimum element. if minimum element > no of planks, vertical will be optimal anyway. Otherwise, make strokes equal to the minimum element and recurse for each side.

Verdict Strong Hire

L3 round 2:
String decode

You are given an encoded string that follows a specific pattern:

The encoding rule is:
k[encoded_string]
where encoded_string inside the square brackets is repeated exactly k times.
k is a positive integer (can be more than one digit).
Encoded strings can be nested inside each other.
The input string is guaranteed to be valid.
Your task:
Return the decoded string.

Input: "3[a]2[bc]"
Output: "aaabcbc"
Explanation: "a" repeated 3 times, then "bc" repeated 2 times

Input: "3[a2[c]]"
Output: "accaccacc"
Explanation: Inside the brackets, "c" is repeated 2 times → "cc",
then "a" + "cc" → "acc", repeated 3 times.

Input: "2[abc]3[cd]ef"
Output: "abcabccdcdcdef"

My Solution:
I started off explaining the recursion and why it is not optimal and finally doing the stack based approach for this and handling edge cases

Verdict: Hire (my guess, because I missed one small case)

L3 round 3:
Standard googliness
Verdict: Strong Hire

Final Verdict:
Recruiter came back within a week. The feedback were super positive, and they want to interview me for L4. I was already on holidays, so we rescheduled for when my holidays were over (I take a month every year)

L4 Interviews

L4 round 1:
You are designing a system to manage elements, each with a unique content (string) and an associated integer score.
The system should support the following two operations:

  • addElement(content, score) Inserts a new element with the given content and score. All contents are guaranteed to be unique at insertion time. Scores can be positive, zero, or negative.
  • getElement() Returns the content of the element with the highest score. Constraint: The same element cannot be returned in consecutive calls.

This restriction only lasts for one turn — if no other element is available, the same element may be returned again.

If the current highest score element is blocked by the "no consecutive" rule, return the next-highest score element.
After an element is returned, its score is decreased by 1, and it remains in the system.

Additional Details & Constraints
All contents are unique — no duplicates in the system.

Returning an element with a lower score is acceptable if the highest score element is blocked due to the "no consecutive" rule.

Scores can become negative after decrements.

The system must always return some element if any exist.

If there are no elements in the system, getElement() returns an empty string.

Example
Operations:
addElement("apple", 5)
addElement("banana", 3)
addElement("cherry", 5)

getElement() → "apple" (highest score = 5)
getElement() → "cherry" (highest score = 5, and "apple" blocked)
getElement() → "apple" (block expired, score now 3, "cherry" was blocked)
getElement() → "cherry" (block expired, score now 3)
getElement() → "banana" (highest score apple blocked, banana also has 3)
State After Each Call:
After 1st get: apple=4, banana=3, cherry=5
After 2nd get: apple=4, banana=3, cherry=4
After 3rd get: apple=3, banana=3, cherry=4
After 4th get: apple=3, banana=3, cherry=3
After 5ht get: apple=3, banana=2, cherry=3 (can also return apple, but not cherry)

My Solution: I used a map for operations and a maxfrequency counter. However, I later realised that a solution with heaps would be optimal here.

Verdict:
Lean Hire -> Did not get time to do the follow up. My fault because the map solution is a bit complex to implement compared to the heap solution and hence, it took me time to handle edge cases

L4 round 2:
You are processing a continuous stream of log entries.
Each log contains:

  • Timestamp — given as a string in "DD-MM-YY HH:MM:SS" format.
  • Message — a string describing the log content.

Logs arrive one at a time, in any order.

Your task is to maintain all logs sorted by timestamp (earliest first).

If two logs have identical timestamps, they must be ordered by insertion order (first in stays first).

You should be able to return the logs as sorted array at any time.

Input / Output Example
Logs arriving in this order:

Log 1 → "20-05-24 10:15:00", "Server started"
Log 2 → "20-05-24 10:14:59", "Auth check"
Log 3 → "20-05-24 10:15:00", "Connection established"
Log 4 → "31-12-23 23:59:59", "Year-end backup"

Sorted logs after all arrivals:

"31-12-23 23:59:59" → "Year-end backup"
"20-05-24 10:14:59" → "Auth check"
"20-05-24 10:15:00" → "Server started" ← came before Log 3
"20-05-24 10:15:00" → "Connection established"

Why this order?

When timestamps are equal, the logs remain in arrival order.

I was told, I can assume an external function to return and process the log in whatever way I want, I just need to write on how will I handle it

My solution: Convert timestamps to epochs and then it is just about maintaining a sorted vector of timestamps to the log message and insert where we find the upper bound to get the first entry with a higher timestamp or last entry with same timestamp and insert there.

Verdict: First mistake: I converted epoch to a string, when I should have kept it as long long for direct comparison, and I got too caught up in the sorted array thing as it was mentioned in the question.
Second mistake: This code, the interviewer found it a bit a complex
Third mistake: I miscommunicated the time complexity for inserting in a vector in the middle
Lean Hire -> Code clarity, modularity, speed and logic was good, missed edge cases and small mistakes, code too complex.

L4 round 3:
Standard Googliness
Verdict: Strong Hire

Overall Verdict:
Had a call with the recruiter that overall L4 feedback is just on the fence and not strong enough to be considered especially since the screening round wasn't promising, it is better we move forward with L3 team matching as L4 can be a possibility of a reject.

Moving forward with L3 team matching.

Comments