Problem 59

18 comments on “Problem 59”


  • sagarbiswasbunny

    import java.util.*;

    public class UniqueElement {

    static int getU(int[] list){
    int unique =0;
    for(int i=0;i<list.length;i++){
    unique = list[i];
    int count=0;
    for(int j=0;j<list.length;j++){
    if(list[j]==unique){
    count++;
    }
    }
    if(count==1){
    return unique;
    }
    }
    return -1;
    }

    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] list = new int[n];
    for(int i=0;i<n;i++){
    list[i]= sc.nextInt();
    }
    int unique= getU(list);
    System.out.println(unique);

    }
    }


  • basava SOWMITH

    list_no=[]
    n= int(input(“Enter the number of values in list to be added”))
    for i in range(0,n):
    value= int(input(“Enter the value”))
    list_no.append(value)

    for i in range(len(list_no)):
    count = 0;
    count=list_no.count(list_no[i])
    if count == 1:
    print(list_no[i])
    break
    count = 0


  • shushank

    #Python

    n=int(input())
    l=list(map(int,input().split(” “)))
    a1=2*sum(list(set(l)))
    a2=sum(l)
    print(a1-a2)


  • 100_18_

    IN PYHTON CODE WOULD BE LIKE :
    def lonelyinteger(nos):
    for i in nos:
    if nos.count(i)==1:
    break
    return i
    n = int(input())
    nos = list(map(int,input().split()))
    print(lonelyinteger(nos))


  • Ninita

    The C++ code for the same

    #include
    using namespace std;

    int main() {
    int count[100];int arr[100]; int n;
    cout<>n; cout<<"\n";
    for(int i=0;i>arr[i];
    }
    for(int i=0;i<n;i++)
    {
    for(int j=0;j<n;j++)
    {
    if(arr[j]==arr[i]&&i!=j)
    {
    count[i]++;
    }
    }
    }

    for(int i=0;i<n;i++)
    {
    if(count[i]==0)
    {
    cout<<"\n"<<arr[i];
    }
    }
    }


  • Pushpak

    import java.util.*;
    public class char_count_String {
    public static void main(String[] args)
    { Scanner sc = new Scanner (System.in);
    int L = sc.nextInt();
    int arr [] = new int [L];
    for(int i =0;i<L;i++) {arr[i]=sc.nextInt();}
    System.out.println(fuction(arr));
    }

    static int fuction(int[] arr) {
    Map hm = new HashMap();
    for(int x : arr) {hm.put(x, hm.getOrDefault(x,0)+1 );}
    for(int x : arr) {if(hm.get(x )==1 )return x;}
    return -1;
    }
    }


  • Sri

    #include
    using namespace std;
    int getLonely(int *arr,int n)
    {
    int res=arr[0];
    for(int i=0;i>n;
    int arr[100];
    for(int i=0;i>arr[i];
    cout<<getLonely(arr,n)<<endl;
    }
    in c++


  • Chanchala singh

    def lonely_integer(a):
    result = 0
    for i in a:
    result ^= i ”’XOR OPERATION
    A^A = 0
    0^B = B So, for each pair of numbers the xor operation results in 0.
    Since there is only one number that does not have a pair, the result is its lonly number,
    since 0^b =b (or b^0 = b).”’
    return result

    n=int(input())
    b = map(int,input().strip().split(” “))
    print(lonely_integer(b))


  • Srimukhi

    #include
    int main()
    {
    int i,a[100],n,j;
    scanf(“%d”,&n);
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    for(i=0;i<n;i++)
    {
    for(j=i+1;j<n;j++)
    {
    if(a[i]==a[j])
    {
    a[i]=0;
    a[j]=0;
    }
    }
    }
    for(i=0;i<n;i++){
    if(a[i]!=0)
    printf("%d",a[i]);
    }
    }
    in c


    • HelpPrepInsta

      Here is a C code for this problem
      #include
      #define MAX_SIZE 100

      int main()
      {
      int arr[MAX_SIZE], freq[MAX_SIZE];
      int size, i, j, count;

      /* Input size of array and elements in array */
      printf(“Enter size of array: “);
      scanf(“%d”, &size);
      printf(“Enter elements in array: “);
      for(i=0; i


      • Tirtha

        n = int(input(‘Enter the number of integers in the array’))
        x = input().split()

        def countUnique(x, n):
        a = []
        for i in range(n):
        if x[i] in a:
        continue
        else:
        a.append(x[i])

        return len(a)

        b = countUnique(x, n)
        print(‘unique elements = {}’.format(b))


    • Mihir

      lst=[1,2,3,4,3,2,1]
      for i in range(len(lst)):
      count=0
      for j in range(len(lst)):
      if (lst[i]==lst[j]) and i!=j:
      count+=1
      if count == 0 :
      print(lst[i])


    • Mihir

      n=int(input(‘Enter a length of list’))
      lst=[]
      for i in range(n):
      lst.append(int(input(” “)))

      for i in range(len(lst)):
      count=0
      for j in range(len(lst)):
      if (lst[i]==lst[j]) and i!=j:
      count+=1
      if count == 0 :
      print(lst[i])