Member-only story

Find Missing Elements in an Array that are Present in Another Array| Coding Interview | Searching

Ganesh Prasad
4 min readOct 7, 2021

--

A’s 1 and 2 are missing in B.

This is an easy problem and it has been asked by Zoho, Accolite, and Snapdeal.

For a better grasp of the problem, after reading each section, try to code that approach. If you get stuck 😉, you can always look at the commented code I have provided for your reference.

This problem is part of the 30 Days Preparation Plan.

Table of Contents

  1. Description
  2. Naive Solution (Brute)
  3. Code
  4. Time & Space Complexity
  5. Efficient Solution
  6. Code
  7. Time & Space Complexity

Description

Given two arrays, A and B, of sizes N and M, respectively. Print all those elements of A that are missing in array B.

Every element of the first array must be present in the second array; if not, you have to print those numbers.

Example 1:
Input: A = [1 6 4 0 2]
B = [6 3 4 5 0]
Output: [1 2]
Explanation: Elements 1 and 2 of A are not present in B, hence the result is 1 and 2.Example 2:
Input: A = [9 8 7 6 5]
B = [1…

--

--

Ganesh Prasad
Ganesh Prasad

Written by Ganesh Prasad

Backend Developer at Appscrip | C++ veteran, 💜 Dart

Responses (1)