Precompute Nearest Target Positions and Define Streaming Answers
Quick Overview
Design static nearest-target queries and a streaming version with explicit answer timing. Compare two-pass preprocessing, target-index searches, and delayed output when future targets may change an answer.
Precompute Nearest Target Positions and Define Streaming Answers
Company: Spotify
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: hard
Interview Round: Onsite
An array contains characters such as `x`, `y`, and `z`. Design a representation that can answer nearest-`z` queries for relevant positions, then explain how you would adapt the task when characters arrive as a stream.
### Clarifications
The reported prompt leaves the relevant positions, tie behavior, return value, and stream latency unspecified. State concrete choices for a worked design, identifying them as practice assumptions. Distinguish the nearest target in the prefix seen so far from the nearest target in the eventual complete stream. Explain whether earlier outputs are provisional, revisable, or delayed.
### What a Strong Answer Covers
Give a complete static preprocessing algorithm and a concrete streaming policy. Address missing targets, ties, consecutive targets, and an indefinitely long gap without a target. Identify what can and cannot be guaranteed without a stream-end signal.
### Follow-up Questions
Could you store only target indices? How would a hard memory limit or a requirement for immediate immutable answers change the contract?
Overview: Design static nearest-target queries and a streaming version with explicit answer timing. Compare two-pass preprocessing, target-index searches, and delayed output when future targets may change an answer.
An array contains characters such as x, y, and z. Design a representation that can answer nearest-z queries for relevant positions, then explain how you would adapt the task when characters arrive as a stream.
Clarifications
The reported prompt leaves the relevant positions, tie behavior, return value, and stream latency unspecified. State concrete choices for a worked design, identifying them as practice assumptions. Distinguish the nearest target in the prefix seen so far from the nearest target in the eventual complete stream. Explain whether earlier outputs are provisional, revisable, or delayed.
What a Strong Answer Covers Guidance
Give a complete static preprocessing algorithm and a concrete streaming policy. Address missing targets, ties, consecutive targets, and an indefinitely long gap without a target. Identify what can and cannot be guaranteed without a stream-end signal.
Follow-up Questions Guidance
Could you store only target indices? How would a hard memory limit or a requirement for immediate immutable answers change the contract?