You are given a string s consisting of lowercase English letters, and an integer k. A substring is defined as 'beautiful' if it can be partitioned into contiguous blocks of identical characters such that: 1. Each block has a length of exactly k. 2. The characters representing each block are in strictly increasing alphabetical order (for example, a block of 'a's followed by a block of 'b's, followed by a block of 'c's). Return the length of the longest beautiful substring in s. If no such substring exists, return 0.
Explanation: The substring "eeefffggghhh" of length 12 can be partitioned into four blocks of size 3: "eee", "fff", "ggg", and "hhh". The block characters 'e', 'f', 'g', and 'h' are in strictly lexicographically increasing order. This is the longest beautiful substring.
Explanation: The entire string "aabbcc" can be partitioned into "aa", "bb", and "cc". Each block has size 2, and the characters 'a', 'b', and 'c' are in strictly increasing order. The maximum length is 6.
Master coding challenges related to Strings and solve the Longest Strictly Increasing K-Block Substring problem optimally.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak