Sort by

recency

|

6034 Discussions

|

  • + 0 comments

    Here is problem solution in Python, Java, C++, C and Javascript - https://programmingoneonone.com/hackerrank-sales-by-match-problem-solution.html

  • + 0 comments

    Python

    def sockMerchant(n, arr): freq={} for i in range(n): if arr[i] in freq: freq[arr[i]]+=1 else: freq[arr[i]]=1 return sum(v//2 for k,v in freq.items())

  • + 0 comments

    a=int(input()) b=list(map(int,input().split())) s=set(b) d=[] w=0 for i in s: r=b.count(i) d.append(r)

    for i in d: if int(i)>=2: t=int(i)//2 w=w+t

    print(w)

  • + 0 comments

    JavaScript

    function sockMerchant(n, ar) {
        let map = new Map();
        let pairs = 0;
        
        for(let s of ar) {
            let socks = map.get(s) ?? 0;
            map.set(s, ++socks);
            if(socks % 2 == 0) ++pairs;
        }
        return pairs;
    }
    
  • + 0 comments

    Here is problem solution in Python, Java, C++, C and Javascript - https://programmingoneonone.com/hackerrank-sales-by-match-problem-solution.html