Please help me to find my error

//https://www.codechef.com/CCSTART2/problems/FINDMELI

class Codechef
{
public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long arr[] = new long[sc.nextInt()];
		long k = sc.nextInt();
		boolean bool = true;

		for (int i = 0; i < arr.length; i++) {
			arr[i] = sc.nextInt();
		}

		for (int j = 0; j < arr.length; j++) {
			if (arr[j] == k) {
				System.out.println(1);
				bool = false;
			}
		}

		if (bool) {
			for (int j = 0; j < arr.length; j++) {
				if (arr[j] != k) {
					System.out.println(-1);
					break;
				}
			}
		}
		sc.close();
	}
}

Did you forget to break the loop?

1 Like