• + 0 comments

    As a Linq lover, I would just do this

    public static int sockMerchant(int n, List<int> ar)
    {
        var ret = ar.GroupBy(x => x).Select(x => new {
            item = x.Key,
            freq = x.Count() / 2
        }).Sum(x => x.freq);
        return ret;
    }`