Sort by

recency

|

6062 Discussions

|

  • + 0 comments

    Python

    def count_elements(n, arr):
        pairs = 0
        count = 0
        for x in arr:
            if n == x:
                count += 1
            if count == 2:
                pairs += 1
                count = 0
        return pairs
    
    def sockMerchant(n, ar):
        count = 0
        numbers = set()
        [numbers.add(x) for x in ar]
        for x in numbers:
            count += count_elements(x, ar)
        return count
    
  • + 0 comments

    While discussing strategies to maximize efficiency in Sales by Match, it’s worth considering how outsourcing certain sales functions can impact overall performance. For businesses looking to scale quickly or tap into specialized expertise, Sales Outsourcing Australia offers a way to handle lead generation, client follow-ups, and closing processes without overextending internal teams. Integrating outsourced support can complement in-house efforts, ensuring that matching supply and demand remains smooth while maintaining high conversion rates.

  • + 0 comments

    Initial solution in JS. I will post an optimized solution later.

    function sockMerchant(n, ar){
      
        let pairCount = 0;
        
        while(ar.length>1) {
          for(let i = 1; i < ar.length; i++) {
            if(ar[0] === ar[i]) {
              pairCount += 1
              ar.splice(0, 1)
              ar.splice(i-1, 1)
              i = 0
            }
          }
          ar.splice(0, 1)
        }
        return pairCount
    
    }
    
  • + 0 comments

    Easy to read code, concise and efficient

    def sockMerchant(n, ar): Sum = 0 for i in list(set(ar)): Sum += ar.count(i)//2 return Sum `

  • + 0 comments
     public static int sockMerchant(int n, List<Integer> ar) {
        // Write your code here
            Map<Integer,Integer> colorCount =new HashMap<>();
            for(int sock : ar ){
                colorCount.put(sock, colorCount.getOrDefault(sock,0)+1);
            }
            
            Integer pairs = 0;
            for(Integer c : colorCount.values()){
                pairs+=c/2;
                
    
            }
            return pairs;
    
        }
    
    }