← Questions
Make your interview solution production-ready
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Google's onsite coding round, last asked Sep 2025. It tests code quality and testing.
You have just written a correct sliding-window solution to a string problem (for example, the longest substring with at most k distinct characters). The interviewer asks: how would you turn this into production code that a shared service calls? Walk through the changes, from the function signature to deployment.
What to cover
- API boundary: a clear signature and contract (inputs, outputs, errors), what the function promises about complexity, and whether it is a library call or a network endpoint.
-
Input validation and encoding:
None, empty strings, invalidk, byte strings versus text, and Unicode. Does "character" mean a code point or a user-perceived character (a grapheme cluster such as an emoji with modifiers)? Normalisation (NFC), so equal-looking strings compare equal. - Large inputs: inputs bigger than memory or than a request should carry; streaming the input in chunks while keeping the window state; hard limits on size.
- Thread safety: a pure function with no shared state, or the locking needed if it caches results.
- Observability: logs without sensitive input, metrics for latency, input size and error rate, and traces through the service.
- Testing: unit tests for edge cases, property-based tests against a brute-force reference, fuzzing with random Unicode, and performance tests at maximum size.
- Security: resource exhaustion (huge inputs, pathological patterns), timeouts and rate limits.
- Rollout: code review, a feature flag or a staged rollout, monitoring and alerts after deploy, and rollback.
Clarifying questions
- Who calls this, how often, and with how large an input?
- Is the input user-controlled (untrusted) or internal?
- What languages and scripts must it handle?
- What should happen on bad input: an error, or a default answer?
What a strong answer covers
- Specific changes to the actual code, not a generic checklist: the new signature, the validation lines, the test cases you would add.
- A decision on Unicode semantics, with an example where code points and graphemes disagree.
- A property-based test that compares the sliding window with an O(n^2) reference on random strings.
- Knowing what to leave out: not every function needs metrics; say what is worth it here and why.
- Complexity documented and enforced by a performance test.
Follow-ups
- The function is now called 50,000 times a second. What changes?
- A customer reports a wrong answer for a string in Thai. How do you debug it?
- How do you make sure a future change doesn't silently make it O(n^2)?
Where it's asked
- Google · Onsite coding · Last asked Sep 202545 min · Usually two rounds, mostly in person: whiteboard plus a Chromebook with Google Docs · No AI (a pilot code-comprehension round lets candidates use Gemini)
What it tests
code quality · testing
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
