Remove duplicates from sorted array

QUESTION

Given a sorted array, the task is to remove the duplicate elements from the array.

“TESTCASE_1”: “5\n2 4 5 5 6\n###—###SEPERATOR—###—\n2 4 5 6”, “TESTCASE_2”: “6\n7 8 9 5 7 7\n###—###SEPERATOR—###—\n7 8 9 5”, “TESTCASE_3”: “7\n8 9 45 45 45 89 369\n###—###SEPERATOR—###—\n8 9 45 89 369”, “TESTCASE_4”: “8\n2 3 4 5 5 7 98 105\n###—###SEPERATOR—###—\n2 3 4 5 7 98 105”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0

ANSWER

#include<stdio.h>
int main(){
int arr[1001]={0},hashing[1001]={0},n,i,temp;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
	scanf("%d",&temp);
	if(hashing[temp]==0)
    {
        arr[i]=temp;
        hashing[temp]++;
    }
}
for(i=1;i<=n;i++)
    {
            if(arr[i]>0)
            {
                printf("%d ",arr[i]);
            }
    }
return 0;
}
 
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock