FunctionRacerProblemsRace

Find Lucky Integer

EasyHash mapsPython, JavaScript, TypeScript, Java, C++

A value is lucky if the number of times it appears in arr equals the value itself. Return the largest lucky value, or -1 if there is none.

Example 1

arr [2,2,3,4]
returns 2

2 appears twice, so it is lucky.

Example 2

arr [1,2,2,3,3,3]
returns 3

1, 2 and 3 are all lucky; the largest is 3.

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