static public int getIdxOfMaxValue(int[][] pairs) {
if (pairs == null || pairs.length == 0) {
return -1;
}
int maxIdx = 0;
int maxVal = pairs[0][1]
for (int i = 1; i < pairs.length; i++) {
if pairs[i][1] > maxVal {
maxVal = pairs[i][1];
maxIdx = i;
}
return maxIdx;
}
/**
*Sorts key-value pairs by value by writing the largest value with its key to a new
*array. The method getIdxOfMaxValue() should be used here. <br>
* If required, Integer.MIN_VALUE can be used here.
*
* @param pairs several pairs in an array (one column = one pair); the key is at the first index,
* the value at the second index
* @return sorted Array of pairs
*/
static public int[][] sortPairs(int[][] pairs) {
if (pairs == null || pairs.length == 0) {
return new pairs[0][0];
}
}
Hey guys, i need a hint or some advice with this method. I don't know how to write the code/the steps. I've already written the method getIdxOfMaxValue.