Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Largest Elements

Implement a function that takes a list of integers and an integer count as input parameters. The purpose of the function is to find the largest count numbers from the provided list.

If the size of the list is less than or equal to 'count', the function should return the original list.

Challenge | Solution

Examples

Example 1

val list = listOf(5, 1, 3)
largestElements(list, 2) shouldBeEqualTo listOf(3, 5)

Example 2

val list = listOf(5, 1, 3)
largestElements(list, 3) shouldBeEqualTo listOf(5, 1, 3)

Hints

Hint 1 Use `PriorityQueue` to store the largest elements.