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
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- 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)
- Maximum number of overlapping string
- Maximum number of removals of given subsequence from a string
- String with maximum number of unique characters
- Maximum number of strings that can be formed with given zeros and ones
- Maximum sum and product of the M consecutive digits in a number
- Number of subarrays with maximum values in given range
- Find the maximum possible Binary Number from given string
- Concatenate strings in any order to get Maximum Number of "AB"
- 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 count number of valley elements in a subarray of size K
- Maximum splits in binary string such that each substring is divisible by given odd number
- Lexicographically smallest K-length substring containing maximum number of vowels
- 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 firstname.lastname@example.org. 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