Trains the technique from
LeetCode 3020Find the Maximum Number of Elements in SubsetThis 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 test rig logs gain readings in readings. An engineer wants to pick a group of those readings, keeping no more copies of a value than the log holds, and lay the picked readings in a row.
The row has to be shaped like this. It opens on some reading. Each step towards the middle squares the reading before it. One reading sits alone in the middle, the largest in the row. After the middle the row descends through exactly the readings it climbed, in reverse, so it reads the same forwards and backwards. A row of a single reading is allowed, with that reading serving as its own middle.
Return the largest number of readings such a row can hold.
Example 1
Laying 3, 9, 3 gives a row that climbs from 3 to its square 9 and comes back down, and the log holds two copies of 3 and one of 9. That row holds three readings.
Example 2
No value appears twice, so no row can climb. A single reading is a valid row, so the answer is 1.
Example 3
Laying 2, 4, 16, 4, 2 uses both copies of 2, both copies of 4 and the single 16 as the middle reading, so the row holds five readings.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def longest_mirror_run(readings: list[int]) -> int:public int longestMirrorRun(int[] readings)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.