Google ng code interview experience

396
Dec 10, 2025

The interviewer started off very chill — after a bit of small talk, he jumped straight into the questions.
And the first one was a classic high-frequency problem:

Problem 1: Subarray Sum Equals K
Given an integer array, find the number of continuous subarrays whose sum equals K.

The moment you hear this question, you know they’re not testing algorithms per se — they’re checking whether you can start with a brute-force solution and progressively optimize it.

The student first mentioned the brute-force approach with O(n²) complexity.
The interviewer smiled, nodded, and then asked:

“If I asked you to optimize it to O(n), how would you think about it?”

At that moment, our voice-assist system hinted:
“Explain the prefix-sum + hashmap idea, don’t rush into coding yet.”

So the student naturally followed up with:
“I’d use a hash map to record how many times each prefix sum has appeared.
While iterating, I check whether prefixSum – K exists — that tells me how many subarrays ending at the current index sum to K.”

He then explained and wrote the solution step by step, even adding the important detail of initializing the map with {0: 1} to correctly handle cases where the subarray from index 0 already equals K.

The interviewer immediately responded:
“Good, that’s the reasoning I’m looking for.”

You can refer to this when preparing for your Google second-round interview.

Comments (0)