Help with this Problem?

So I have been trying to solve a problem

SALARY

Here is the code.

import java.util.Arrays;
import java.util.Scanner;

class Salary {	
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int T = in.nextInt();
		int arr[];
		while(T-->0){
			int N = in.nextInt();
			int steps = 0;
			arr = new int[N];
			for(int i=0;i<N;i++){
				arr[i] = in.nextInt();
			}
			Arrays.sort(arr);
			int indexL = N -1 ; 	
			for(int i =0 ;i<arr.length-1;i++){
				steps+= arr[indexL]- arr[i];
			}
			System.out.println(steps);
		}
		in.close();
	}
}

Can anybody point the error in this code?

Consider test case :

Input

1

3

2 1 1

Expected ouput :

1

Your Output :

2

Look at @vijju 's explanation and my solution(although I didn’t come up with the solution :))

1 Like

alright, understood the error, thanks!

No problem bro!!