Cognizant Coding Question- 7

2 comments on “Cognizant Coding Question- 7”


  • ashu.835

    arr = list(map(int,input().split()))
    a1 = []
    for i in range(0, len(arr)):
    if arr[i] not in a1:
    a1.append(arr[i])
    print(a1)


  • 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]);

    }
    }