Cognizant Coding Question- 7

One comment on “Cognizant Coding Question- 7”


  • Aqib

    solution:
    import java.util.*;
    public class RemoveReppeatedElements {
    public static void main(String args[])
    {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int ans=0;
    int arr[]=new int[n];
    for(int i=0;i<n;i++)
    arr[i]=sc.nextInt();
    Arrays.sort(arr);
    for(int i=0;i<arr.length-1;i++)
    {
    if(arr[i]!=arr[i+1])
    System.out.print(arr[i]+" ");
    }
    System.out.print(arr[arr.length-1]);

    }
    }