Optimal way to Compare two arrays that are widely different I have two different arrays that are widely different in length, arrayA, arrayB

for example:arrayA.Length=1000  and arrayB.Length=100,000

Create a boolean function that returns true if each item in arrayA are also  present in arrayB, at least the same number of times as in arrayA.

Please review my code below and help me with siuggestions to improve this code below

    private static bool IsMinRequiredFrequencyMatch(int[] arrA,int[] arrB)
    {
    bool result = false;        
    Array.Sort(arrA);

    //create dictionary from shorter array 
    var dict = new Dictionary&lt;int, int&gt;();
    for (int i = 0; i &lt; arrA.Length; i++)
    {
        var ch = arrA[i];
        if (!dict.ContainsKey(ch))
        {
            dict[ch] = 1; //add char count
        }
        else
        {
            dict[ch]++; //increase count
        }
    }




    //loop through Dictionary
    foreach (var kvp in dict)
    {
        var chr = kvp.Key; //target item to find
        var expectedcount = kvp.Value; //expected count of item in arrB
        int actualCount = 0; //actual count of item in arrB

        //loop through arrayB
        for (int i = 0; i &lt; arrB.Length; i++)
        {
            if (arrB[i] == chr)
            {
                actualCount++;
            }

            if (actualCount &gt;= expectedcount)
            {
                result = true;
                break;
            }
        }

        if (actualCount &lt; expectedcount)
        {
            result = false;             
            break;
        }
    }

    return result;


}
Sure, you can always write your own method for everything but if you are lazy you could just use LINQ with ToLookup + All + Count

var arr1 = new[] { 1, 2, 3, 4, 3, 2 };
var arr2 = new[] { 6, 7, 3, 4, 1, 2, 2, 3 };

var lookup1 = arr1.ToLookup(x =&gt; x);
var lookup2 = arr2.ToLookup(x =&gt; x);

var isFullyContained = lookup1.All(x =&gt; lookup2[x.Key].Count() == x.Count());


false - means arr1 is fully contained in arr2

The good thing about lookup is that you don't need the ContainsKey method because if the key does not exist it'll return an empty collection.



Review

You create a dictionary only for the first array but you need one for the second array too or otherwise you need to loop over it each time which is unnecessary. Just count the items and compare their counts.