All problems
0153EasyArray

Turntable Weight Order

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1752Check if Array Is Sorted and Rotated

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 pottery studio loads clay trays onto a circular turntable, one tray per station around the rim. House procedure says the loader picks any station to begin at and then works clockwise around the full circle, never putting on a tray lighter than the one just placed. Two trays of equal weight next to each other are perfectly fine.

An inspector arrives later and reads the weights off clockwise into the array weights, but the inspector begins at whichever station happens to face the doorway, which is not usually the station the loader began at. So the reading is the loader's ordering turned around the rim by some unknown number of stations.

Decide whether the reading is consistent with house procedure: return true when some station exists such that reading weights clockwise from it, all the way around, never steps down in weight, and false when no station does that. The inspector's own starting station counts, so a reading that never steps down as written is consistent.

Examples

Example 1

Input
weights = [7, 9, 4, 5, 6]
Output
true

Beginning at the station holding 4 and going clockwise gives 4, 5, 6, 7, 9, which never steps down, so the loader could have started there.

Example 2

Input
weights = [5, 3, 8, 6]
Output
false

Reading clockwise from each station in turn gives 5, 3, 8, 6 then 3, 8, 6, 5 then 8, 6, 5, 3 then 6, 5, 3, 8. Every one of those steps down somewhere, so no station is consistent with procedure.

Example 3

Input
weights = [4, 4, 4]
Output
true

Equal weights are allowed side by side, so the reading never steps down at all and any station works.

Constraints

  • 1 <= weights.length <= 100
  • 1 <= weights[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 turntable_weight_order(weights: list[int]) -> bool:
Java
public boolean turntableWeightOrder(int[] weights)
September 7
Apply