Leetcode 1510 Solution

This article provides solution to leetcode question 1510 (find-lucky-integer-in-an-array)

https://leetcode.com/problems/find-lucky-integer-in-an-array

Solution

class Solution:
    def findLucky(self, arr: List[int]) -> int:
        m = collections.defaultdict(int)
        for v in arr:
            m[v] += 1
        for k, v in sorted(m.items(), reverse=True):
            if k == v:
                return v
        return -1