FastPrepRectangle Fit Queries

Rectangle Fit Queries

Hudson River Trading logoHudson River Trading● MediumNEW GRADINTERNOA
Learn

Problem statement

Process the rows of operations from left to right. Each row has one of two forms:

  • [0, a, b]: create and save a rectangle of size a × b.
  • [1, a, b]: determine whether every rectangle saved by earlier operations can fit inside a box of size a × b.

Test each saved rectangle separately; the rectangles do not need to fit in the box at the same time. You may rotate a rectangle by 90 degrees.

Return one boolean for each query operation, in query order.

Function

solution(operations: int[][]) → boolean[]

Examples

Example 1

operations = [[1,1,1]]return = [true]

No rectangles have been saved, so every saved rectangle vacuously fits and the answer is true.

Example 2

operations = [[0,1,3],[0,4,2],[1,3,4],[1,3,2]]return = [true,false]

Both saved rectangles fit the 3 × 4 box after choosing the appropriate orientation. The 4 × 2 rectangle cannot fit the later 3 × 2 box, so the answers are [true,false].

Constraints

  • operations contains at least one row.
  • operations[i].length = 3.
  • operations[i][0] is either 0 or 1.
  • operations[i][1] and operations[i][2] are positive integers.

Source note: The second panel is a tighter source-faithful view of the two HRT examples for easier reading.

More Hudson River Trading problems

See Hudson River Trading hiring insights
public boolean[] solution(int[][] operations) {
  // Write your code here.
}
operations[[1,1,1]]
expected[true]
Checking account…