Loading content...
You are working with a binary signal transmission system where each signal pulse is represented by either 'H' (high voltage) or 'L' (low voltage). For reliable data transmission over noisy channels, it is ideal to have the longest possible contiguous segment of uniform signals—either all high or all low pulses.
A signal engineer can modify the transmission by flipping up to maxFlips signal pulses, changing an 'H' to 'L' or vice versa. Your task is to determine the maximum length of a contiguous uniform signal segment that can be achieved after performing at most maxFlips flip operations.
Given a string signalPattern where signalPattern[i] represents the signal type at position i (either 'H' for high or 'L' for low), and an integer maxFlips representing the maximum number of allowed flip operations, return the maximum length of a contiguous segment containing only 'H' signals or only 'L' signals that can be formed.
signalPattern = "HHLL"
maxFlips = 24We can flip both 'L' signals to 'H' signals, resulting in "HHHH". This gives us a contiguous segment of 4 uniform high voltage signals.
signalPattern = "HLLH"
maxFlips = 13We can flip the first 'H' to 'L' to get "LLLH", creating a segment of 3 consecutive 'L' signals. Alternatively, flipping the second 'H' to 'L' gives "HLLL" with 3 consecutive 'L' signals. Either approach yields a maximum uniform segment of length 3.
signalPattern = "HHLHHLHH"
maxFlips = 15Flipping the first 'L' gives "HHHHHLLHH", creating a segment of 5 consecutive 'H' signals. Alternatively, flipping the second 'L' gives "HHLHHHHHH", also resulting in 5 consecutive 'H' signals. The maximum achievable uniform segment is 5.
Constraints