john sokpo

Generation

translateFri, 07 Jul 2023

class Solution: def maxConsecutiveAnswers(self, string: str, k: int) -> int: result = 0 j = 0 count1 = k for i in range(len(string)): if count1 == 0 and string[i] == "F": while string[j] != "F": j+=1 count1+=1 j+=1 if string[i] == "F": if count1 > 0: count1-=1 if i - j + 1 > result: result = i - j + 1 j = 0 count2 = k for i in range(len(string)): if count2 == 0 and string[i] == "T": while string[j] != "T": j+=1 count2+=1 j+=1 if string[i] == "T": if count2 > 0: count2-=1 if i - j + 1 > result: result = i - j + 1 return result

<?php $str = "ABCD"; $n = strlen($str); printAllKLength($str, $n, 3); function printAllKLength($str, $n, $k) { // Base case: k is 0, // print prefix if ($k == 0) { echo $str . "\n"; return; } // One by one add all characters // from set and recursively // call for k equals to k-1 for ($i = 0; $i < $n; ++$i) { // Next character of input added $newstr = substr($str, 0, $i) . substr($str, $i + 1); // k is decreased, because // we have added a new character printAllKLength($newstr, $n - 1, $k - 1); } } ?>

Want to kickstart your project?Use the new AI Studio to create your code