admin@onlinelearningcenter.in (+91) 7 999 01 02 03

Remove all occurance of Number from an Array

Suraj Ghimire
13 Posts

Given an array of N and a number n, remove all occurance of that number  from an array if number is present

 

Example 1:

arr={1,2,3,4,5}

num=4 (number to be removed)

 

Output: {1,2,3,5,-1} Since 4 is removed, 5 will take it place. We will fill up left over with -1

 

Example 2:

arr={1,2,3,4,5}

num =6 (number to be removed,but is not present)

 

Output: {1,2,3,4,5} Since element was not present, nothing will be removed.

 

Example 3:

 

arr={1,2,3,4,5,4}

num=4 (number to be removed)

 

Output :{1,2,3,5,-1,-1} Since both 4 are removed, 5 will go forward and then the left over place will be filled up by -1

Published By : Suraj Ghimire
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Comments

Jquery Comments Plugin