Not able to pass all the test cases

@shivank.agg.sa In the if condition that you have used
if (arr[j] < arr[i]) {
val = j;
}
in the if condition instead of arr[i] you have to use arr[val] bcoz if in previous iteration val was updated you are comparing i but you have to compare val indexed element. Therefore corrected if statement is :
if (arr[j] < arr[val]) {
val = j;
}