Given a large number as string s and an integer k which denotes the number of breakpoints we must put in the number k <= string length. The task is to find maximum segment value after putting exactly k breakpoints.
Input : s = "8754", k = 2 Output : Maximum number = 87 Explanation : We need to two breakpoints. After putting the breakpoints, we get following options 8 75 4 87 5 4 The maximum segment value is 87. Input : s = "999", k = 1 Output : Maximum Segment Value = 99 Explanation : We need to one breakpoint. After putting the breakpoint, we either get 99,9 or 9,99.
One important observation is, the maximum would always be of length “string-length – k” which is the maximum value of any segment. Considering the fact, problem becomes like sliding window problem means we need to find maximum of all substrings of size (string-length – k).
Maximum number = 87
- Check if number can be displayed using seven segment led
- Maximize the given number by replacing a segment of digits with the alternate digits given
- Maximum number of splits of a binary number
- Longest Common Extension / LCE | Set 3 (Segment Tree Method)
- String with maximum number of unique characters
- Concatenate strings in any order to get Maximum Number of "AB"
- Maximum number of removals of given subsequence from a string
- Number of subarrays with maximum values in given range
- Maximum sum and product of the M consecutive digits in a number
- Find the maximum possible Binary Number from given string
- Maximum number of characters between any two same character in a string
- Maximum number of Unique integers in Sub-Array of given size
- Find the number in a range having maximum product of the digits
- Maximum number of given operations to remove the entire string
- Maximum number of times str1 appears as a non-overlapping substring in str2
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : PranchalKatiyar