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 int key; public int value;

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!