Sort an array according to the increasing frequency of the digit K in the array elements

#include
using namespace std;
  

int countOccurrences(int num, int K)
{
    
    if (K == 0 && num == 0)
        return 1;
  
    
    int count = 0;
  
    
    while (num > 0) {
        if (num % 10 == K)
            count++;
        num /= 10;
    }
  
    
    return count;
}
  

void sortOccurrences(int arr[],
                     int N, int K)
{
    
    
    multimap mp;
  
    
    for (int i = 0; i < N; i++) {                              int count = countOccurrences(             arr[i], K);                     mp.insert(pair(             count, arr[i]));     }             for (auto& itr : mp) {         cout