Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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