Skip to content

Files

Latest commit

7dd5fe5 · Jul 25, 2023

History

History
This branch is 4 commits behind igorwojda/kotlin-coding-challenges:main.

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.