We’re preparing your current view and syncing the latest data.
Given an integer array arr and an integer k, you need to find the maximum subarray sum in the array formed by concatenating arr k times. The subarray can be empty, and the result should be given modulo 10^9 + 7. A subarray is a contiguous part of an array.
Return the maximum subarray sum modulo 10^9 + 7 seen in the concatenated array.
Example 1
Input
arr = [1, -2, 1], k = 3
Output
2
Explanation
The concatenated array is [1, -2, 1, 1, -2, 1, 1, -2, 1]. The maximum subarray sum is 2 (from subarray [1, 1]).