All problems
0875EasyArraySimulation

Settling the Gauge Row

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1243Array Transformation

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 row of gauges reads arr. Every round, all the gauges are updated at once from the readings the row held at the start of that round:

  • a gauge with a neighbour on each side rises by one when both neighbours read higher than it, and falls by one when both read lower;
  • otherwise it keeps its reading, and the gauges at the two ends never change.

Rounds continue until a round changes nothing. Return the row as it then stands.

Examples

Example 1

Input
arr = [1, 3, 2, 3]
Output
[1, 2, 3, 3]

In the first round the gauge reading 3 at position 1 has 1 and 2 either side, both lower, so it falls to 2, while the gauge reading 2 has 3 and 3 either side, both higher, so it rises to 3. The next round changes nothing.

Example 2

Input
arr = [5, 1, 5]
Output
[5, 5, 5]

The middle gauge rises by one each round while both neighbours stay higher, and it stops once it reaches them.

Example 3

Input
arr = [1, 2, 3]
Output
[1, 2, 3]

The middle gauge has one neighbour above and one below, so it never moves, and the two ends never move either.

Constraints

  • 3 <= arr.length <= 100
  • 1 <= arr[i] <= 100

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 settle_gauges(arr: list[int]) -> list[int]:
Java
public List<Integer> settleGauges(int[] arr)
September 7
Apply