Smallest Range Covering Elements from K Lists
Smallest Range Covering Elements from K Lists
Hello, young coder! Today, we're on an exciting journey to find the smallest range that covers at least one element from each of the given lists.
Imagine you have a few different bags, each filled with colorful marbles, but they are in different bags (represented as lists). Your task is to find the smallest range of numbers on the number line such that there is at least one marble from each bag lying within this range. Isn't that fun?
Here's a more detailed explanation: You are given k sorted lists of integers. Your mission, should you choose to accept it, is to find the smallest range [a, b] such that at least one number from each of the k lists is contained in the closed interval [a, b]. If there are multiple solutions, you can return any of them.
Examples:
# Example 1: lists = [[4, 10, 15, 24, 26], [0, 9, 12, 20], [5, 18, 22, 30]] # Explanation: The smallest range is [20, 24] because it covers 24 from the first list, 20 from the second list, and 22 from the third list. smallest_range(lists) # Output: [20, 24] # Example 2: lists = [[1, 5, 10], [4, 7, 8], [4, 6, 9]] # Explanation: The smallest range is [4, 5] which covers 5 from the first list, 4 from the second list, and 4 from the third list. smallest_range(lists) # Output: [4, 5]
Unleash your clever coding skills and try to come up with a solution!
Happy coding!
Inputs
Arg 1:
[[4,10,15,24,26],[0,9,12,20],[5,18,22,30]]Expected Output
[20, 24]Actual Output