C program to remove duplicates in an array

C program to remove duplicates in an array

Removing duplicates from an array is a very common interview question. For your reference, we have written the program and its compiled and tested.  If you are preparing for the interview make sure you learn the code logic and try implementing it on your own.

LOGIC

The core logic to remove duplicates is to iteratively check for the item existence. For this, we will use one additional temporary array and a few counter variables i, j, k, and flag variable exists. In the program we transfer items one after the other from one array to other, while we do this we make sure its not already in the new array. 


/*
	Program to remove duplicate numbers from an array
	Author 			: 		Krishna Teja G S
	Repository		:		github.com/packetprep/coding-questions
	Website			: 		packetprep.com
*/

#include

int main(){

	int arr[] = {100, 5, 201, 13, 5, -8,12,-8,3,-8}; 
	int i,j,k,key,exists;
	int arr_size = sizeof(arr)/sizeof(int); 
	int arr_2[100]={0};

	printf("Elements: \n");

	for(i=0;i
wipro free mock test
Wipro National Qualifier Test is just a few days away. To help you crack the exam we are sharing a mock test specially designed for Wipro based on all the previous papers.