Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

Learn everything about programming

HackerRank Missing Numbers problem solution

YASH PAL, 31 July 202430 November 2025

In this HackerRank Missing Numbers problem solution Given two arrays of integers, find which elements in the second array are missing from the first array.

HackerRank Missing Numbers problem solution

Problem solution in Python.

from collections import Counter

k1 = input()
c1 = Counter(map(int, input().split()))
k2 = input()
c2 = Counter(map(int, input().split()))

if k1 > k2:
    c2, c1 = c1, c2
    
l = []
for k in c2.keys():
    if k not in c1 or c1[k] < c2[k]:
        l.append(k)
        
print(' '.join(map(str, sorted(l))))

{“mode”:”full”,”isActive”:false}

Problem solution in Java.

import java.io.*;
import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] A = new int[n];

        for (int i = 0; i < n; i++) {
            A[i] = in.nextInt();
        }

        int m = in.nextInt();
        int[] B = new int[m];

        for (int i = 0; i < m; i++) {
            B[i] = in.nextInt();
        }

        HashMap<Integer, Integer> freqs = new HashMap<Integer, Integer>();

        for (int i = 0; i < m; i++) {
            if (freqs.containsKey(B[i])) {
                int freq = freqs.get(B[i]);
                freqs.replace(B[i], freq + 1);
            } else {
                freqs.put(B[i], 1);
            }
        }

        for (int i = 0; i < n; i++) {
            if (freqs.containsKey(A[i])) {
                int freq = freqs.get(A[i]);
                if (freq == 1) {
                    freqs.remove(A[i]);
                } else {
                    freqs.replace(A[i], freq - 1);
                }
            } else {
                System.out.println("error");
            }
        }

        StringBuilder answer = new StringBuilder();
        Iterator it = freqs.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry pair = (Map.Entry)it.next();
            answer.append(pair.getKey());
            answer.append(" ");
        }

        System.out.println(answer.toString());
    }
}

{“mode”:”full”,”isActive”:false}

Problem solution in C++.

#include<iostream>

using namespace std;

const int maxn = 10000;

int A[maxn*2 + 5];

int main() {
  int n, m;
  int xmin = maxn, xmax = -maxn;
  cin >> n;
  for( int i = 0; i<n; i++ ) {
    int tmp;
    cin >> tmp;
    A[tmp] --;
  }
  cin >> m;
  for( int i = 0; i<m; i++ ) {
    int tmp;
    cin >> tmp;
    A[tmp] ++;
    if (xmax < tmp) { xmax = tmp; }
    if (xmin > tmp) { xmin = tmp; }
  }
  for( int i=xmin; i<=xmax; i++ ) {
    if( A[i] > 0 ) {
      cout << i << " ";
    }
  }
  return 0;
}

{“mode”:”full”,”isActive”:false}

Problem solution in C.

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

#define read_int(x) scanf("%d", &x)
#define RANGE 100
#define BASE_IDX (RANGE + 1)
#define COUNT_SIZE (RANGE * 2)

int main() {
    
    int m, n; 
    int base, k, i;
    int count[COUNT_SIZE];
    
    memset(count, 0, COUNT_SIZE * sizeof(int));
    
    read_int(m);
    read_int(k);
    base = k;
    count[BASE_IDX] = 1;
    for (i = 1; i < m; i++) {
        read_int(k);
        count[BASE_IDX + (k - base)]++;
    }
    
    read_int(n);  
    for (i = 0; i < n; i++) {
        read_int(k);
        count[BASE_IDX + (k - base)]--;
    }

    for (i = 0; i < COUNT_SIZE; i++) {
        if (count[i] < 0) printf("%d ", base + (i - BASE_IDX));
    }
    printf("n");
  
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */    
    return 0;
}

{“mode”:”full”,”isActive”:false}

Algorithms coding problems solutions AlgorithmsHackerRank

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes