Find Lucky Integer in an Array (LeetCode #1394)
This is a problem taken from LeetCode. The original problem statement:
Given an array of integers arr, a lucky integer is an integer which has a frequency in the array equal to its value.
Return a lucky integer in the array. If there are multiple lucky integers return the largest of them. If there is no lucky integer return -1.
In Python, this is clearly a problem that requires a Counter object. This will give us counts of each value in the array and then all we need to do is compare the keys to the values in the counter object.