Obstacle Placement Queries
Reported by candidates from Capital One's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Capital One OA reported in September 2026 has a problem called Obstacle Placement Queries, and the first attempt usually dies on one thing: scanning the whole block for every query. You get a stream of operations on an infinite number line. Some place obstacles, others ask if a block of length size fits right before coordinate x. It looks like simulation, but it's really an ordered-set lookup. If you blank on the data structure in the live OA, StealthCoder is the safety net that reads the screen and hands you a working solution without the proctor seeing it.
The problem
A special thank-you to the friend who kindly shared that this problem was seen again on August 4, 2026! ദ്ദി(ᵔᗜᵔ) You are given an infinite number line and an array operations. Process the operations in order while maintaining the coordinates that contain obstacles. [1, x]: Place an obstacle at coordinate x. Coordinate x is guaranteed to contain no obstacle when this operation is performed. [2, x, size]: Check whether a block of length size can end immediately before coordinate x. The block would occupy every integer coordinate from x - size through x - 1. Append '1' to the answer if none of those coordinates contains an obstacle; otherwise append '0'. This operation only checks feasibility and does not place the block. Return the binary string formed by the results of all type-2 operations in their original order. Function obstaclePlacementQueries(operations: int[][]) → String Examples Example 1 operations = [[2, 0, 2], [1, 1], [2, 0, 2], [2, 2, 2]] return = "110" [2, 0, 2] checks coordinates -2 and -1. There are no obstacles, so append 1. [1, 1] places an obstacle at coordinate 1. [2, 0, 2] still checks coordinates -2 and -1. Both are free, so append 1. [2, 2, 2] checks coordinates 0 and 1. Coordinate 1 contains an obstacle, so append 0.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The mistake that sinks a first attempt is brute force. Checking every coordinate from x - size to x - 1 per query costs O(size), and with large sizes and many operations that times out. The trick is to ask a different question: what is the largest obstacle coordinate strictly less than x? If that obstacle is below x - size, the block fits and you append 1. Otherwise append 0. So you need a predecessor query on a dynamic set of obstacles. In Python, use a sorted list with bisect, though insertion is O(n). A balanced tree, TreeSet floor, or a segment tree over compressed coordinates gives O(log n). Offline, you can read all operations first and compress coordinates. Watch the off-by-one: the block covers x - size through x - 1, so an obstacle at exactly x - size blocks it, but one at x doesn't. StealthCoder is your hedge if the structure choice escapes you mid-assessment.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Obstacle Placement Queries cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Capital One's OA.
Capital One reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Obstacle Placement Queries FAQ
What's the trick in Obstacle Placement Queries?+
Stop checking each cell. For a type-2 query, find the nearest obstacle strictly left of x. If its coordinate is at least x - size, the block is blocked and you append 0. If no such obstacle exists or it's smaller than x - size, append 1.
How hard is this Capital One OA question really?+
Medium. The logic is short once you see the predecessor idea. The difficulty is picking a structure that supports insert and nearest-lower lookup fast. If you've used TreeSet, sorted containers, or bisect, it's very doable.
Can I just use a plain list and bisect.insort?+
It works for correctness, and the search is O(log n), but insertion shifts elements, giving O(n) per placement. For small inputs it passes. For large ones, a balanced tree, or offline coordinate compression with a segment tree or Fenwick tree, is safer.
Where do off-by-one errors happen here?+
The block occupies x - size through x - 1 inclusive. An obstacle at x - size blocks it. An obstacle at x does not. Test with the example: query [2, 2, 2] covers 0 and 1, and the obstacle at 1 gives 0.
How do I prepare for this in 48 hours?+
Practice predecessor and successor queries on a dynamic ordered set in your language. Write the query by hand, then trace the sample to get "110". Also rehearse an offline approach with coordinate compression as a backup. That covers most variants of this problem.