Question
In Java, Given an Array X with n distinct elements, create an array Y where all elements are in range 0 to n -1 and
In Java,
Given an Array X with n distinct elements, create an array Y where all elements are in range 0 to n -1 and the order of elements is the same as in X. This means, 0 has the same index in Y as the smallest element in X, 1 has the same index in Y as the 2nd tiniest element in X. i.e. x=[8,11,2,9], means Y=[1,3,0,2].
I can't create helper functions outside of the following code block.
this is the code so far:
import java.io.*; import java.util.*;
public class Lab2 {
/** * Problem 2: Determines for each entry its position in the sorted array. */ private static int[] problem2(int[] arr) { // here return new int[] { }; }
// --------------------------------------------------------------------- // Do not change any of the code below!
static class IntKVPair implements Comparable
public IntKVPair(int key, int value) { this.key = key; this.value = value; }
public int compareTo(IntKVPair other) { return this.key - other.key; }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started