Find Majority Element [I am unable to find problem in this solution can you help me with that]

import java.util.*;
public class Main {
public static void main (String args[]) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int[] nums = new int[n];

    for (int i = 0; i < n; i++) {
        nums[i] = scn.nextInt();
    }

    int count1 = 0, count2 = 0, Elem1 = 0, Elem2 = 0;

    for (int i : nums) {
        if (i == Elem1) {
            count1++;
        }
        else if (i == Elem2) {
            count2++;
        }
        else if (count1 == 0) {
            Elem1 = i;
            count1++;
        }
        else if(count2 == 0){
            Elem2 = i;
            count2++;
        }
        else{
            count1--;
            count2--;
        }
    }

    //Verification
    count1 =0; count2 =0;

    for(int i : nums){
        if(i == Elem1){
            count1++;
        }
        else if( i == Elem2){
            count2++;
        }
    }

    if(count1 > count2){
        System.out.println(Elem1);
    }
    else if(count2 > count1){
        System.out.println(Elem2);
    }
    else if (count1 == count2){
        System.out.println(Elem1 + " " + Elem2);
    }
    else{
        System.out.println("No Majority Elements");
    }
}

}

@ak1928verma_463c9afb34c7a150 you have to print the elements in increasing order. So do something which will print element in increasing order.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.