Notice Period

Warehouse Grid Search

medium

A warehouse stores part numbers in a grid of bins: each row is sorted left to right, and the first number of each row is greater than the last number of the row above — so reading the grid row by row gives one fully sorted sequence.

Given the grid bins and a part number part, return True if the part exists in the grid, else False. Aim for O(log(rows × cols)).

Example 1
in bins = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], part = 3
out True
Example 2
in bins = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], part = 13
out False
Constraints
  • · 1 <= rows, cols <= 100
  • · -10^4 <= bins[i][j], part <= 10^4
  • · rows are sorted; each row starts after the previous row ends
similar problem on LeetCode ↗
solution.pyloading python…
test results
Hit ▶ Run to test your code against the visible cases.