e an array of size k by concatenating contiguous segments of the input array. Example: Input: [1, 2, 3, 4], 6 Output: 2 Explanation: The minimum number of contiguous segments that must be concatenated to form an array of size 6 is 2. The two segments that can be concatenated are [1, 2] and [3, 4]. Input: [1, 2, 3, 4], 7 Output: -1 Explanation: It is not possible to create an array of size 7 by concatenating contiguous segments of the input array. Constraints: The input array arr will have at most length 100. The integer k will be at least 1 and at most 10^6. Can you write a C# function that solves this problem? public int GetMinimumCutSegments(int[] arr, int k) { // Your code here }
Implement a function GetMinimumCutSegments(int[] arr, int k) that takes in an array arr of positive integers and an integer k, and returns the minimum number of contiguous segments of the array that must be concatenated to form an array of size k.
The function should return -1 if it is not possible to create an array of size k by concatenating contiguous segments of the input array.
Example:
Input: [1, 2, 3, 4], 6
Output: 2
Explanation:
The minimum number of contiguous segments that must be concatenated to form an array of size 6 is 2. The two segments that can be concatenated are [1, 2] and [3, 4].
Input: [1, 2, 3, 4], 7
Output: -1
Explanation:
It is not possible to create an array of size 7 by concatenating contiguous segments of the input array.
Constraints:
The input array arr will have at most length 100.
The integer k will be at least 1 and at most 10^6.
Can you write a C# function that solves this problem?
public int GetMinimumCutSegments(int[] arr, int k) { // Your code here }
Step by step
Solved in 3 steps with 1 images