Quick Overview

Check fixed board intervals against sorted number-line blockers, with explicit endpoint rules, duplicate blockers, and independent placement queries.

Check Fixed Board Placements Against Number-Line Blockers

Company: Capital One

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Online Assessment

You are given point blockers on an infinite number line and proposed boards, each with a fixed starting coordinate and length. Determine independently whether each board can be placed without covering a blocker. Implement `can_place_boards(blockers: int[], boards: int[][]) -> bool[]`. Each board row is `[start, length]`. Return one Boolean per board in input order. ### Constraints & Assumptions - For this deterministic practice version, a board occupies the half-open interval `[start, start + length)`. A blocker at the start prevents placement; one exactly at the end does not. - The report's examples do not resolve endpoint contact. The half-open convention is an explicit practice assumption. - Lengths are positive integers at most 1,000,000,000. Blocker coordinates and board starts range from -1,000,000,000 through 1,000,000,000. - There are at most 200,000 blockers and 200,000 boards. Blockers may be unsorted or repeated. - All blockers are fixed before the checks. A successful check does not place a permanent board or affect later checks. - The board must start at the specified coordinate. Do not search for a different location or a free subinterval within a larger prefix. ### Examples ```text blockers = [3,7,11] boards = [[0,2],[5,3]] result = [true,false] ``` The second board covers coordinate 7. ```text blockers = [3] boards = [[1,2],[3,1],[4,1]] result = [true,false,true] ``` The first board ends exactly at 3 and does not include that coordinate under the chosen convention. ```hint Find the nearest relevant blocker For a board starting at a fixed coordinate, blockers to its left cannot matter. Consider the first blocker at or to the right of that start. ```

Overview: Check fixed board intervals against sorted number-line blockers, with explicit endpoint rules, duplicate blockers, and independent placement queries.

Read the full Capital One Software Engineer interview experience this question came from

You are given point blockers on an infinite number line and proposed boards, each with a fixed starting coordinate and length. Determine independently whether each board can be placed without covering a blocker. Implement `can_place_boards(blockers: int[], boards: int[][]) -> bool[]`. Each board row is `[start, length]`. Return one Boolean per board in input order. ### Constraints & Assumptions - For this deterministic practice version, a board occupies the half-open interval `[start, start + length)`. A blocker at the start prevents placement; one exactly at the end does not. - The report's examples do not resolve endpoint contact. The half-open convention is an explicit practice assumption. - Lengths are positive integers at most 1,000,000,000. Blocker coordinates and board starts range from -1,000,000,000 through 1,000,000,000. - There are at most 200,000 blockers and 200,000 boards. Blockers may be unsorted or repeated. - All blockers are fixed before the checks. A successful check does not place a permanent board or affect later checks. - The board must start at the specified coordinate. Do not search for a different location or a free subinterval within a larger prefix. ### Examples ```text blockers = [3,7,11] boards = [[0,2],[5,3]] result = [true,false] ``` The second board covers coordinate 7. ```text blockers = [3] boards = [[1,2],[3,1],[4,1]] result = [true,false,true] ``` The first board ends exactly at 3 and does not include that coordinate under the chosen convention. ```hint Find the nearest relevant blocker For a board starting at a fixed coordinate, blockers to its left cannot matter. Consider the first blocker at or to the right of that start. ```

Constraints

  • At most 200000 blocker coordinates and 200000 board rows; blockers may be unsorted or repeated.
  • Coordinates and board starts range from -1000000000 through 1000000000; lengths are positive and at most 1000000000.
  • Each board occupies [start,start+length): a blocker at start prevents placement, one at the end does not.
  • Checks are independent against fixed blockers. Do not move the specified start or persist successful placements.
  • Return one boolean per board in input order.

Examples

Input: ([3, 7, 11], [[0, 2], [5, 3]])

Expected Output: [True, False]

Explanation: A blocker strictly inside the second interval prevents placement.

Input: ([3], [[1, 2], [3, 1], [4, 1]])

Expected Output: [True, False, True]

Explanation: The end is excluded but the start is included.

Loading coding console...

Show the approach

Approach

Sort the fixed blocker coordinates once, retaining duplicates harmlessly. For a board starting at s, binary-search the first blocker b>=s. All preceding blockers lie outside the board. If no such b exists, the interval is clear; otherwise it is clear exactly when b>=s+length. Equality at the end is allowed by the half-open convention, while equality at the start fails because length is positive. This nearest relevant blocker is sufficient because every later blocker is at least as far right. Process each board independently without changing blockers or searching a replacement location. For B blockers and Q boards, sorting takes O(B log B) and checks O(Q log(B+1)), with O(B) copied/sorted state plus results. Java/C++ use wide endpoint arithmetic, and JavaScript integers are exact for the stated bounds.

Time complexity:
O(B log(B+1) + Q log(B+1))
Space complexity:
O(B) auxiliary state plus output