All problems
1184MediumArrayHash TableMathGreedy

The Smallest Reading the Rack Cannot Reach

Tracked in this browser only
Write code

Trains the technique from

LeetCode 2598Smallest Missing Non-negative Integer After Operations

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 rack holds the readings readings. Each reading may be raised or lowered by step, as often as you like and each independently of the others.

Once the changes are made, return the smallest whole number from 0 upwards that is not among the readings.

Examples

Example 1

Input
readings = [0, 1, 2, 3], step = 4
Output
4

Each reading leaves a different remainder against four, so 0 through 3 can all be reached, and reaching 4 would need a second reading leaving no remainder.

Example 2

Input
readings = [7], step = 5
Output
0

The single reading leaves a remainder of two against five, so it can never be brought to 0.

Example 3

Input
readings = [0, 0, 1, 1], step = 2
Output
4

Two readings leave no remainder and two leave one, so 0, 1, 2 and 3 are all reachable and 4 would need a third even reading.

Constraints

  • 1 <= readings.length <= 10^5
  • 1 <= step <= 10^5
  • -10^9 <= readings[i] <= 10^9

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 find_smallest_integer(readings: list[int], step: int) -> int:
Java
public int findSmallestInteger(int[] readings, int step)
September 7
Apply