FunctionRacerProblemsRace

Count Elements With a Next

BeginnerHash mapsPython, JavaScript, TypeScript, Java, C++

Count the items x in arr such that x + 1 also appears somewhere in arr. If a value is repeated, count each copy separately.

Example 1

arr [1,2,3]
returns 2

1 (2 is present) and 2 (3 is present) count; 3 does not.

Example 2

arr [1,1,3,3,5,5,7,7]
returns 0

No item has its successor in the list.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Hash maps problems