john sokpo

Generation

translateFri, 07 Jul 2023

var maxConsecutiveAnswers = function(answerKey, k) { let [left, right, numOfTrue, numOfFalse, max] = new Array(5).fill(0); const moreChanges = () => numOfTrue > k && numOfFalse > k; while (right < answerKey.length) { if(answerKey[right] === 'T') numOfTrue++; if(answerKey[right] === 'F') numOfFalse++; while(moreChanges()) { if(answerKey[left] === 'T') numOfTrue--; if(answerKey[left] === 'F') numOfFalse--; left++; } max = Math.max(max, right - left + 1); right++; } return max; };

class Solution { /** * @param Integer[] $nums * @param Integer $target * @return Integer[] */ function twoSum($nums, $target) { $hash = []; foreach ($nums as $i => $value) { $complement = $target - $value; if (isset($hash[$complement])) { return [$hash[$complement], $i]; } $hash[$value] = $i; } } }

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