Trains the technique from
LeetCode 509Fibonacci NumberThis 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 ramp generator on a test rig publishes a numbered stream of readings. Reading 0 comes out as 0 and reading 1 comes out as 1. From then on the register produces reading k by totalling the two readings it published immediately beforehand, that is reading k - 1 and reading k - 2.
The stream therefore opens 0, 1, 1, 2, 3, 5, 8 and carries on.
Given an index n, return reading n.
Example 1
The stream opens on 0, and no totalling is needed.
Example 2
Readings 5 and 6 come out as 5 and 8, and totalling them gives reading 7.
Example 3
Working up the stream one reading at a time reaches 987 at index 16.
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 cascade_reading(n: int) -> int:public int cascadeReading(int n)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.