Answered step by step
Verified Expert Solution
Link Copied!

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 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Database And Knowledge Base Systems

Authors: S Krishna

1st Edition

9810206208, 978-9810206208

More Books

Students also viewed these Databases questions

Question

2. Identify the purpose of your speech

Answered: 1 week ago