Sales by Match

  • + 0 comments

    C# Code

    public static int sockMerchant(int n, List<int> ar)
        {
            int pairCount = 0;
            
            var groupList = ar.Order()
                .GroupBy(e => e)
                .Select(e => new { SockId = e.Key, Count = e.Count() })
            .ToList();
            
            foreach(var sockGroup in groupList)
            {
                pairCount += sockGroup.Count / 2;
            }
            
            return pairCount;
        }