Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

find lucky integer in an array javascript leetcode

 
This is post to find Lucky Integer in an Array Javascript Leetcode solution. For problem statement click here



Javascript program to find lucky integer in an array

 
var findLucky = function(arr) {
    let max = -1, hash = {};
     
    for (let a of arr) {
        if (!hash[a]) {
            hash[a] = 1;
        } else {
            hash[a]++;
        }
    }
 
    for (let key in hash) {
        if (key == hash[key]) {
            max = Math.max(key, max);
        }
    }
 
    return max;
};


Time Complexity : O(n)
Space Complexity : O(n)

 
 


This post first appeared on CodeforJS, please read the originial post: here

Share the post

find lucky integer in an array javascript leetcode

×

Subscribe to Codeforjs

Get updates delivered right to your inbox!

Thank you for your subscription

×