All problems
0070MediumArrayBinary SearchMatrix

Paged Offset Lookup

Tracked in this browser only
Write code

Trains the technique from

LeetCode 74Search a 2D Matrix

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A calibration archive keeps signed offset readings in fixed-width pages. You are given pages, a list of m pages of n readings each, laid out so that:

  • readings grow strictly from left to right inside a page, and
  • every reading on a page is strictly smaller than every reading on the page after it.

Given an integer probe, report whether that exact reading is filed anywhere in the archive.

Return true when the archive holds probe, otherwise false. The archive can be large, so your lookup must run in time logarithmic in the total reading count m * n; walking every page is too slow.

Examples

Example 1

Input
pages = [[-9, -4, 1], [6, 11, 20]], probe = 11
Output
true

Reading 11 sits in the second slot of the second page, so the archive holds it.

Example 2

Input
pages = [[-9, -4, 1], [6, 11, 20]], probe = 5
Output
false

Nothing between 1 and 6 was ever filed, so 5 is absent even though it falls inside the archive's range.

Example 3

Input
pages = [[-10], [0], [10]], probe = 10
Output
true

Pages of a single reading are allowed; the last page carries 10.

Constraints

  • m == pages.length
  • n == pages[i].length
  • 1 <= m, n <= 100
  • -10^4 <= pages[i][j], probe <= 10^4
  • Readings ascend across the whole archive when the pages are read in order

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def locate_offset(pages: list[list[int]], probe: int) -> bool:
Java
public boolean locateOffset(int[][] pages, int probe)
September 7
Apply