Sales by Match

  • + 0 comments

    Scala

    def sockMerchant(n: Int, ar: Array[Int]): Int = {
            val distinctSocks = ar.distinct
            
            var pairs: Int = 0
            for(i <- distinctSocks) {
                pairs+= (ar.count(_==i))/2
            }
            pairs
        }