Loading...
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.
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.
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.
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.
s.length ≤5×104s[i] is either 'T' or 'F's.lengthClick "Run" to test with sample cases or "Submit" to run all tests.