Question: Please note that all methods must be written from scratch; preexisting methods or libraries cannot be used for this assignment. public class ArrayProblems { /

Please note that all methods must be written from scratch; preexisting methods or libraries cannot be used for this assignment.
public class ArrayProblems {
/*
Given an array of integers nums, sort the array in ascending order.
Example 1:
Input: nums =[5,2,3,1]
Output: [1,2,3,5]
Example 2:
Input: nums =[5,1,1,2,0,0]
Output: [0,0,1,1,2,5]
*/
public static int[] sortArray(int[] nums){
//TODO:finish this method.
//TODO: Modify this line to return correct data.
return null;
}
/*
* Find the kth largest element in an unsorted array.
* Note that it is the kth largest element in the sorted order, not the kth distinct element.
Example1: Input: [3,2,1,5,6,4] and k =2
Output: 5
Example2: Input: [3,2,3,1,2,4,5,5,6] and k =4
Output: 4
*/
public static int findKthLargest(int[] nums, int k){
//TODO:finish this method.
//TODO: Modify this line to return correct data.
return 0;
}
}
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class ArrayProblemsTest {
@BeforeEach
void setUp() throws Exception {
}
/*
sortArray CASE 1:
Input: nums =[5,2,3,1]
Output: [1,2,3,5]
*/
@Test
void testSortArray1(){
int[] nums={5,4,3,1};
int[] expected ={1,3,4,5};
assertArrayEquals(expected, ArrayProblems.sortArray(nums));
}
/*
sortArray CASE 2:
Input: nums =[5,1,1,2,0,0]
Output: [0,0,1,1,2,5]
*/
@Test
void testSortArray2(){
fail("Not yet implemented"); // TODO
}
/*
findKthLargest test case1:
Input: [3,2,1,5,6,4] and k =2
Output: 5
*/
@Test
void testFindKthLargest1(){
fail("Not yet implemented"); // TODO
}
/*
findKthLargest test case1:
Input: [3,2,3,1,2,4,5,5,6] and k =4
Output: 4
*/
@Test
void testFindKthLargest2(){
fail("Not yet implemented"); // TODO
}
}
Please complete them with adding comments too

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!