```python class Solution: def countTriplets(self, A: List[int]) -> int: “”” tc O(N^2) sc O(1) prefix XOR assuming a = A[i] ^ A[i+1] ^...A[j-1], b = A[j]^A[j+1]^...A[k] main idea3: - a == b => a^a == a^b => A[i]^A[i+1]^...A[k] == 0 => prefix[k+1] = prefix[i] - find out how many pair(i,k)...
[Read More]
1371. Find the Longest Substring Containing Vowels in Even Counts
```python class Solution: def findTheLongestSubstring(self, s: str) -> int: “"”tc O(N) sc O(2^M) use a counter to get # each vowels if in substring, if vowel = 0, can keep increasing XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX main idea: bit mask. note it's not about counting number of each vowels in string. it's check if...
[Read More]
930. Binary Subarrays With Sum
class Solution: def numSubarraysWithSum(self, A: List[int], goal: int) -> int: """ tc O(N) sc O(1) (assuming each item in A is non-negtive ) 1. corner case if target < 0 2. left, right ptr start with head. start with K, keep substract current item the right ptr pointing at 3....
[Read More]
301. Remove Invalid Parentheses
```python class Solution: def removeInvalidParentheses(self, s: str) -> List[str]: “"”tc O(2^N) sc O(N) return all results => backtracking? (maintain current path valid) + with minimun removal =how to determine valid? ==> main idea: generate unique answer exactly once (no rely on set) to find out last removal position, we need...
[Read More]
1882. Process Tasks Using Servers
```python class Solution: def assignTasks(self, servers: List[int], tasks: List[int]) -> List[int]: “”” tc O(SlgS+T*lgT) sc O(S) main idea: two PQ “”” available = [[w,j] for j,w in enumerate(servers)] # (weight,idex) unava = [] # (available at time ,w, idx) heapq.heapify(available) cur_t = 0 n = len(tasks) res = []#[-1] *n...
[Read More]