A fitness-tracking app assigns every logged workout an integer intensity rating. Analysts consider a logged workout to be part of a progression if there exists some other logged workout, anywhere in the log and not necessarily adjacent to it, whose intensity rating is exactly one greater. Every entry in the log is checked independently, so if the same rating value appears multiple times and it has a qualifying successor rating somewhere in the log, every one of those repeated entries counts separately.
Given the full list of logged intensity ratings, in the order they were logged, report how many logged entries are part of a progression.
n, the number of logged workouts.n space-separated integers, the intensity ratings, in the order they were logged.Print a single integer: the number of entries x in the log for which the value x + 1 also appears somewhere in the log.
Example 1
Input
3 1 2 3
Expected
2
Explanation
1 has a successor 2 in the log, so it counts. 2 has a successor 3 in the log, so it counts. 3 has no 4 in the log, so it does not count. Total: 2.
Example 2
Input
3 1 1 2
Expected
2
Explanation
Both occurrences of 1 have a successor 2 present in the log, so each counts separately, giving 2. The single 2 has no 3 in the log, so it does not count. Total: 2.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →