Virtusa Polaris Interview Question – Part – II
This blog explains about Virtusa Polaris Interview Question – Part – II especially for the freshers including questions for programming . They are given below :
We have already discussed about some questions in the previous blog . Some of the few are illustrated below :
REFERENCE : (Virtusa Polaris Interview Question – Part – I )
_______________________________________________________________________________
1. Write a program to delete duplicate elements from an array .
Required knowledge
Basic Input Output, If else, For loop, Nested loop, Array
Logic to delete duplicate elements from array
Step by step descriptive logic to delete duplicate elements from array.
- Input size and elements in arrayfrom user. Store it in some variable say size and arr.
- To find duplicate elements in given array we need two loops. Run an outer loop from 0 to size. Loop structure must look like for(i=0; i<size; i++). This loop is used to select each element of array and check next subsequent elements for duplicates using another nested loop.
- Run another inner loop to find first duplicate of current element. Run an inner loop from i + 1to size. The loop structure should look like for(j=i+1; j<size; j++).
- Inside the inner loop check for duplicate element. If a duplicate element is found then delete that array element. Also if a duplicate element is found then decrement size of array i.e. size = size – 1
Example
Input
Input array elements:
10, 20, 10, 1, 100, 10, 2, 1, 5, 10
Output
After removing all duplicate elements
Elements of array are: 10, 20, 1, 100, 2, 5
_______________________________________________________________________________
REFERENCES :
https://codeforwin.org/2015/07/c-program-to-delete-duplicate-elements-from-array.html