Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Find the smallest after deleting given elements using C++
In this problem, we are given two arrays arr[] and del[]. Our task is to find the smallest after deleting given elements.
We will be deleting values from the array arr[] that are present in del[]. And then print the smallest value after deletion.
Let’s take an example to understand the problem,
Input
arr[] = {2, 5, 6, 9, 1}
del[] = {1, 5, 9}
Output
2
Solution Approach
A simple solution to the problem is using hashing. We will insert all the values of del[] array in the hash table. Then we will traverse the array arr[] and check if the values in the hash table. If it is smaller than minVal. If yes, print minVal.
Example
Program to illustrate the working of our solution
#includeusing namespace std; int findSmallestVal(int arr[], int m, int del[], int n){ unordered_map delVals; for (int i = 0; i Output
The smallest value after the deleting element is 12
Advertisements
