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 :
Input: nums
Output:
Example :
Input: nums
Output:
public static int sortArrayint 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.
Example: Input: and k
Output:
Example: Input: and k
Output:
public static int findKthLargestint nums, int k
TODO:finish this method.
TODO: Modify this line to return correct data.
return ;
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 :
Input: nums
Output:
@Test
void testSortArray
int nums;
int expected ;
assertArrayEqualsexpected ArrayProblems.sortArraynums;
sortArray CASE :
Input: nums
Output:
@Test
void testSortArray
failNot yet implemented"; TODO
findKthLargest test case:
Input: and k
Output:
@Test
void testFindKthLargest
failNot yet implemented"; TODO
findKthLargest test case:
Input: and k
Output:
@Test
void testFindKthLargest
failNot 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
