0 out of 464 challenges solved
Write a Python function to find the largest sum of a contiguous subarray in a modified array formed by repeating a given array `k` times. The function should take the array, its length, and the repetition count as inputs. #### Example Usage ```python [main.nopy] # Example 1 arr = [10, 20, -30, -1] n = len(arr) k = 3 print(max_sub_array_sum_repeated(arr, n, k)) # Expected output: 30 # Example 2 arr = [-1, 10, 20] n = len(arr) k = 2 print(max_sub_array_sum_repeated(arr, n, k)) # Expected output: 59 # Example 3 arr = [-1, -2, -3] n = len(arr) k = 3 print(max_sub_array_sum_repeated(arr, n, k)) # Expected output: -1 ``` #### Constraints - The input array can contain both positive and negative integers. - The repetition count `k` is a positive integer. - The function should handle edge cases such as all negative numbers in the array.
def max_sub_array_sum_repeated(a, n, k): """ Find the largest sum of a contiguous subarray in the modified array formed by repeating the given array k times. Parameters: a (list): The input array. n (int): The length of the input array. k (int): The number of times the array is repeated. Returns: int: The largest sum of a contiguous subarray. """ # Placeholder for the implementation pass