Given an array of integers arr, a lucky integer is an integer that has a frequency in the array equal to its value.

Return the largest lucky integer in the array. If there is no lucky integer return -1.

&nbsp;
Example 1:

Input: arr = [2,2,3,4]
Output: 2
Explanation: The only lucky number in the array is 2 because frequency[2] == 2.


Example 2:

Input: arr = [1,2,2,3,3,3]
Output: 3
Explanation: 1, 2 and 3 are all lucky numbers, return the largest of them.


Example 3:

Input: arr = [2,2,2,3,3]
Output: -1
Explanation: There are no lucky numbers in the array.


&nbsp;
Constraints:


	1 &lt;= arr.length &lt;= 500
	1 &lt;= arr[i] &lt;= 500


class Solution:
    def findLucky(self, arr: List[int]) -> int:
        dc = {}
        
        for i in range(len(arr)):
            if arr[i] not in dc:
                dc[arr[i]] = 1
            else:
                dc[arr[i]] = dc[arr[i]] + 1
        mx = -1
        for key,value in dc.items():
            if key == value:
                mx = max(key, mx)
        return mx
class Solution {
    public int findLucky(int[] arr) {
        HashMap<Integer,Integer> map = new HashMap<>();
        for(int i : arr){
            map.put(i, map.getOrDefault(i,0)+1);
        }
        System.out.print(map);
         int max = 0;
        for (Map.Entry<Integer, Integer> e : map.entrySet()){
           int temp = 0;
            if(e.getKey() == (int)e.getValue()){
                temp = (int)e.getKey();
            }
            if(max < temp){
                max= temp;
            }
        }
         if(max != 0)return max;
        return -1;
    }
}
class Solution {
public:
    int findLucky(vector<int>& arr) {
        // sort(arr.begin(),arr.end());
        map<int,int>mp;
        vector<int>v;
        for(int i=0;i<arr.size();i++)
        {
            mp[arr[i]]++;
        }

        for(auto x:mp)
        {
            if(x.first == x.second)
            {
                v.push_back(x.first);
            }
           
        }

        int mx = -1;
        for(int i=0;i<v.size();i++)
        {
            mx = max(mx,v[i]);
        }



        return mx;
        
    }
};
/**
 * @param {number[]} arr
 * @return {number}
 */
 
var findLucky = function(arr) {
	let obj = {};
	arr.map((num) => {
		obj[num] = obj[num] + 1 || 1;
	});

	let answer = -1;
	for (let key in obj) {
		if (Number(key) === obj[key]) answer = Math.max(answer, Number(key));
	}

	return answer;
};
Find Lucky Integer in an Array