You are given a string s consisting only of the two characters 'T' and 'F', and an integer k.
In one operation you may set any character of s to either 'T' or 'F'. You may perform at most k such operations.
Return the length of the longest contiguous segment of s that consists of a single repeated character (all 'T' or all 'F') that can be achieved after performing at most k operations.
Examples
Example 1
Input: s = "TTFF", k = 2
Output: 4
Explanation: Change both 'F's to 'T' to obtain "TTTT". The whole string is one run of four 'T's.
Example 2
Input: s = "TFFT", k = 1
Output: 3
Explanation: Change the first 'T' to 'F' to obtain "FFFT", or the last 'T' to 'F' to obtain "TFFF". Either way there is a run of three 'F's.
Example 3
Input: s = "TTFTTFTT", k = 1
Output: 5
Explanation: Change one of the two 'F's to 'T', giving "TTTTTFTT" or "TTFTTTTT". Either way there is a run of five 'T's.
Constraints
1≤s.length≤5×104
s[i] is either 'T' or 'F'
1≤k≤s.length
Loading editor...
Log in to run your code. Your draft is saved in this browser.Log inSign up