My issue
My code
import java.util.Scanner;
class Codechef {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int m = scanner.nextInt();
int n = scanner.nextInt();
int x = scanner.nextInt();
int[][] matrix = new int[m][n];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
matrix[i][j] = scanner.nextInt();
}
}
int result = findMinimumOperations(matrix, x);
System.out.println(result);
}
private static int findMinimumOperations(int[][] matrix, int x) {
int m = matrix.length;
int n = matrix[0].length;
// Check if it's possible to make all elements equal
int remainder = matrix[0][0] % x;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (matrix[i][j] % x != remainder) {
return -1; // It's not possible to make all elements equal
}
}
}
// Calculate the minimum number of operations
int target = matrix[0][0];
int operations = 0;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
int diff = Math.abs(matrix[i][j] - target);
operations += diff / x;
}
}
return operations;
}
}
Problem Link: EQUALARRAY Problem - CodeChef
Please help me the understand the problem i am unable to understand.