My code fails for a single test case and i cant debug it. the test case is no.1 for which my code fails

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Majority_element {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	
	Scanner scn = new Scanner(System.in);
	
	int n = scn.nextInt();
	
	int[] arr = new int[n];
	for(int i=0; i<n; i++) {
		arr[i] = scn.nextInt();
	}
	
	solve(arr);
}

static void solve(int[] arr) {
	
	int n = arr.length;
	HashMap<Integer, Integer> map = new HashMap<>();
	
	for(int i=0; i<n; i++) {
		
		if(map.containsKey(arr[i])) {
			int ov = map.get(arr[i]);
			int nv = ov+1;
			map.put(arr[i], nv);
		}else {
			map.put(arr[i], 1);
		}
	}
	boolean flag = false;
	ArrayList<Integer> keys = new ArrayList<>(map.keySet());
	for(int key:keys) {
		if(map.get(key) > (n/3)) {
			System.out.print(key +" ");
			flag = true;
		}
	}
	if(flag == false) {
		System.out.println("No Majority Elements");
	}
}

}

hello @zoovier20
ur code is correct, because of order of the output u are getting wa.

cb judge dont accept multiple valid solutions so for this problem .try submitting it over leetcode or use approach that is given in editorial

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.