0 out of 464 challenges solved
Write a Python function `reverse_array_upto_k(arr, k)` that takes a list `arr` and an integer `k` as input and returns a new list where the first `k` elements of the array are reversed, while the rest of the array remains unchanged. #### Example Usage ```python [main.nopy] reverse_array_upto_k([1, 2, 3, 4, 5, 6], 4) # Output: [4, 3, 2, 1, 5, 6] reverse_array_upto_k([4, 5, 6, 7], 2) # Output: [5, 4, 6, 7] reverse_array_upto_k([9, 8, 7, 6, 5], 3) # Output: [7, 8, 9, 6, 5] ``` #### Constraints - `k` will always be a positive integer. - `k` will not exceed the length of the array. - The input array will not be empty.
def reverse_array_upto_k(arr, k): """ Reverse the first k elements of the array. Args: arr (list): The input list of elements. k (int): The number of elements to reverse from the start. Returns: list: A new list with the first k elements reversed. """ # Placeholder for the solution pass