Leetcode Problem 1394. Find Lucky Integer in an Array

1394. Find Lucky Integer in an Array

Leetcode Solutions

Approach: Counter

  1. Initialize an empty HashMap counts.
  2. Iterate over each number num in the array arr.
    • If num is not in counts, add it with a count of 1.
    • If num is already in counts, increment its count.
  3. Initialize largest_lucky_number to -1.
  4. Iterate over each entry in the counts HashMap.
    • If the key (number) is equal to the value (count) and the key is larger than largest_lucky_number, update largest_lucky_number.
  5. Return largest_lucky_number.
UML Thumbnail

Approach: Brute Force

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...