Question: Implement a Python function that finds the k largest items in a list. DO NOT USE ANY BUILD IN FUNCTIONS. Implement find _ k _
Implement a Python function that finds the k largest items in a list. DO NOT USE ANY BUILD IN FUNCTIONS.
Implement findklargestnumskfunction that takes a list nums of integers and an integer k as parameters. The function should return a list containing the k largest items in descending order.
## TESTING findklargest function
## DO NOT EDIT THIS CELL.
def testfindklargest:
# Test Case : Positive Integers
nums
k
expected
assert findklargestnums k expected fTest Case failed: Expected expected but got findklargestnums k
# Test Case : Negative Integers
nums
k
expected
assert findklargestnums k expected fTest Case failed: Expected expected but got findklargestnums k
# Test Case : Mixed Integers
nums
k
expected
assert findklargestnums k expected fTest Case failed: Expected expected but got findklargestnums k
# Test Case : Duplicate Integers
nums
k
expected
assert findklargestnums k expected fTest Case failed: Expected expected but got findklargestnums k
# Test Case : Empty List
nums
k
expected
assert findklargestnums k expected fTest Case failed: Expected expected but got findklargestnums k
# Test Case : List with Fewer than k items
nums
k
expected
assert findklargestnums k expected fTest Case failed: Expected expected but got findklargestnums k
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
