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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- 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
- Longest Common Extension / LCE | Set 3 (Segment Tree Method)
- Find value after N operations to remove N characters of string S with given constraints
- Maximum length substring having all same characters after k changes
- Maximum contiguous 1 possible in a binary string after k rotations
- Maximum length of balanced string after swapping and removal of characters
- Find the maximum occurring character after performing the given operations
- Maximum non-repeating characters after removing K characters
- Convert Hexadecimal value String to ASCII value String
- Extract maximum numeric value from a given string | Set 1 (General approach)
- Extract maximum numeric value from a given string | Set 2 (Regex approach)
- Calculate maximum value using '+' or '*' sign between two numbers in a string
- Python Regex to extract maximum numeric value from a string
- Arrange a binary string to get maximum value within a range of indices
- Maximum sum of a Matrix where each value is from a unique row and column
- Reduce the number to minimum multiple of 4 after removing the digits
- Find the number obtained after concatenation of binary representation of M and N
- Check if string remains palindrome after removing given number of characters
- Count of primes after converting given binary number in base between L to R
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