description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.
Return the minimum number of function calls to make nums from arr.
The answer is guaranteed to fit in a 32-bit signed integer.
Example 1:
Input: nums = [1,5]
Output: 5
Explanation: Increment by 1 (second eleme... | class Solution:
def minOperations(self, nums: List[int]) -> int:
lim = len(nums)
test = [0] * lim
t = 0
while nums != test:
vals = []
v = 0
for i in range(0, lim):
if nums[i] % 2 == 0:
vals.append(nums[i] // 2)
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR... |
Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.
Return the minimum number of function calls to make nums from arr.
The answer is guaranteed to fit in a 32-bit signed integer.
Example 1:
Input: nums = [1,5]
Output: 5
Explanation: Increment by 1 (second eleme... | class Solution:
def minOperations(self, nums: List[int]) -> int:
goal = [0] * len(nums)
if nums == goal:
return 0
calls = 0
div_needed = False
for i in range(len(nums)):
if nums[i] % 2 == 1:
nums[i] -= 1
calls += 1
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR NU... |
Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.
Return the minimum number of function calls to make nums from arr.
The answer is guaranteed to fit in a 32-bit signed integer.
Example 1:
Input: nums = [1,5]
Output: 5
Explanation: Increment by 1 (second eleme... | class Solution:
def minOperations(self, nums: List[int]) -> int:
count = 0
while 1:
for i, vi in enumerate(nums):
if vi & 1:
count += 1
nums[i] = vi - 1
chk = True
for i, vi in enumerate(nums):
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER WHILE NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER RETURN VAR VAR |
Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.
Return the minimum number of function calls to make nums from arr.
The answer is guaranteed to fit in a 32-bit signed integer.
Example 1:
Input: nums = [1,5]
Output: 5
Explanation: Increment by 1 (second eleme... | def adjust2power(n):
if n == 0:
return 0
for i in range(1, n + 1):
if 1 << i >= n:
if n % (1 << i) != 0:
i -= 1
break
return 1 << i
def howManyPower(n):
for i in range(1, n + 1):
if 1 << i == n:
return i
class Solution:
... | FUNC_DEF IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER RETURN BIN_OP NUMBER VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR VAR RETURN VAR CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST A... |
Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.
Return the minimum number of function calls to make nums from arr.
The answer is guaranteed to fit in a 32-bit signed integer.
Example 1:
Input: nums = [1,5]
Output: 5
Explanation: Increment by 1 (second eleme... | class Solution:
def minOperations(self, nums: List[int]) -> int:
count = {}
def iseven(n):
return n % 2 == 0
ans = 0
for n in nums:
count[n] = count.get(n, 0) + 1
keys = list(count.keys())
for n in keys:
if n == 0:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT FUNC_DEF RETURN BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN... |
Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.
Return the minimum number of function calls to make nums from arr.
The answer is guaranteed to fit in a 32-bit signed integer.
Example 1:
Input: nums = [1,5]
Output: 5
Explanation: Increment by 1 (second eleme... | def get_num_ops(num):
assert num >= 0
d_ops, s_ops = 0, 0
while num != 0:
if num % 2 == 1:
num = num - 1
s_ops += 1
else:
num = num // 2
d_ops += 1
return d_ops, s_ops
class Solution:
def minOperations(self, nums: List[int]) -> int:
... | FUNC_DEF VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR VAR CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VA... |
Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.
Return the minimum number of function calls to make nums from arr.
The answer is guaranteed to fit in a 32-bit signed integer.
Example 1:
Input: nums = [1,5]
Output: 5
Explanation: Increment by 1 (second eleme... | class Solution:
def minOperations(self, nums: List[int]) -> int:
res = 0
while nums != [0] * len(nums):
for i in range(len(nums)):
if nums[i] == 1:
nums[i] -= 1
res += 1
elif nums[i] % 2 == 1:
nu... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VA... |
Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.
Return the minimum number of function calls to make nums from arr.
The answer is guaranteed to fit in a 32-bit signed integer.
Example 1:
Input: nums = [1,5]
Output: 5
Explanation: Increment by 1 (second eleme... | def ops(x):
if x == 1:
return 0, 1
if x % 2 == 0:
d, i = ops(x // 2)
return d + 1, i
else:
d, i = ops(x - 1)
return d, i + 1
class Solution:
def minOperations(self, nums: List[int]) -> int:
increments = 0
max_doubles = 0
for x in nums:
... | FUNC_DEF IF VAR NUMBER RETURN NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR BIN_OP VAR NUMBER CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN ... |
Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.
Return the minimum number of function calls to make nums from arr.
The answer is guaranteed to fit in a 32-bit signed integer.
Example 1:
Input: nums = [1,5]
Output: 5
Explanation: Increment by 1 (second eleme... | class Solution:
def minOperations(self, nums: List[int]) -> int:
count = 0
nums = [num for num in nums if num]
if not nums:
return 0
while nums:
flag = False
new_nums = []
for num in nums:
if num % 2:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR IF VAR RETURN NUMBER WHILE VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR FOR VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_... |
Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.
Return the minimum number of function calls to make nums from arr.
The answer is guaranteed to fit in a 32-bit signed integer.
Example 1:
Input: nums = [1,5]
Output: 5
Explanation: Increment by 1 (second eleme... | class Solution:
def minOperations(self, nums: List[int]) -> int:
c = 1
count = 0
maxn = max(nums)
while c * 2 <= maxn:
c = c * 2
count += 1
@lru_cache
def dfs(n):
if n <= 1:
return n
elif n % 2 == 0:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN VAR IF BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR FO... |
Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.
Return the minimum number of function calls to make nums from arr.
The answer is guaranteed to fit in a 32-bit signed integer.
Example 1:
Input: nums = [1,5]
Output: 5
Explanation: Increment by 1 (second eleme... | class Solution:
def soln(self, nums, ans, e, o):
if len(nums) == 0:
return ans
for i in nums:
if i % 2 == 0 and i != 0:
e.append(i)
elif i != 0:
o.append(i)
ans += len(o)
for i in range(len(o)):
o[i] -= ... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN VAR FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ... |
Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.
Return the minimum number of function calls to make nums from arr.
The answer is guaranteed to fit in a 32-bit signed integer.
Example 1:
Input: nums = [1,5]
Output: 5
Explanation: Increment by 1 (second eleme... | class Solution:
def minOperations(self, nums: List[int]) -> int:
result = 0
while nums:
new = []
for x in nums:
if x > 0:
if x != 1:
new.append(x - (x & 1))
result += x & 1
nums = new... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR VAR |
Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.
Return the minimum number of function calls to make nums from arr.
The answer is guaranteed to fit in a 32-bit signed integer.
Example 1:
Input: nums = [1,5]
Output: 5
Explanation: Increment by 1 (second eleme... | class Solution:
def minOperations(self, nums: List[int]) -> int:
ans = 0
while not all(n == 0 for n in nums):
div = 0
for i, n in enumerate(nums):
if n & 1:
ans += 1
n -= 1
if n > 0:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR RETURN VAR VAR |
Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.
Return the minimum number of function calls to make nums from arr.
The answer is guaranteed to fit in a 32-bit signed integer.
Example 1:
Input: nums = [1,5]
Output: 5
Explanation: Increment by 1 (second eleme... | class Solution:
def minOperations(self, nums: List[int]) -> int:
x = [0] * len(nums)
counts = 0
while 1:
counts += sum(n % 2 for n in nums)
nums = [(n // 2) for n in nums]
if nums == x:
return counts
counts += 1
def di... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR RETURN VAR VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NONE VAR VAR NUM... |
Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.
Return the minimum number of function calls to make nums from arr.
The answer is guaranteed to fit in a 32-bit signed integer.
Example 1:
Input: nums = [1,5]
Output: 5
Explanation: Increment by 1 (second eleme... | class Solution:
def minOperations(self, nums: List[int]) -> int:
count = 0
while True:
for i in range(len(nums)):
if nums[i] == 1:
nums[i] = 0
count += 1
if max(nums) < 1:
break
for i in rang... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER WHILE NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER RETURN VAR VAR |
Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.
Return the minimum number of function calls to make nums from arr.
The answer is guaranteed to fit in a 32-bit signed integer.
Example 1:
Input: nums = [1,5]
Output: 5
Explanation: Increment by 1 (second eleme... | class Solution:
def minOperations(self, nums: List[int]) -> int:
memo = {(0): (0, 0)}
def helper(num):
if num not in memo:
if num % 2 == 1:
a, b = helper(num - 1)
memo[num] = a + 1, b
else:
a, b... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR NUMBER FOR... |
Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.
Return the minimum number of function calls to make nums from arr.
The answer is guaranteed to fit in a 32-bit signed integer.
Example 1:
Input: nums = [1,5]
Output: 5
Explanation: Increment by 1 (second eleme... | class Solution:
def minOperations(self, nums: List[int]) -> int:
count = 0
while True:
Zero = True
for i in range(len(nums)):
if nums[i] & 1:
nums[i] -= 1
count += 1
if nums[i]:
Zero ... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR RETURN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR |
Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.
Return the minimum number of function calls to make nums from arr.
The answer is guaranteed to fit in a 32-bit signed integer.
Example 1:
Input: nums = [1,5]
Output: 5
Explanation: Increment by 1 (second eleme... | class Solution:
def minOperations(self, nums: List[int]) -> int:
lst = list(map(find_op, nums))
mul = max(lst, key=lambda x: x[0])
mul = mul[0]
add = sum([item[1] for item in lst])
return add + mul
def find_op(n):
mul, add = 0, 0
while n > 0:
if n % 2 == 1:... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR RETURN BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBE... |
Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.
Return the minimum number of function calls to make nums from arr.
The answer is guaranteed to fit in a 32-bit signed integer.
Example 1:
Input: nums = [1,5]
Output: 5
Explanation: Increment by 1 (second eleme... | class Solution:
def minOperations(self, nums: List[int]) -> int:
def get_add_mul_times(num: int):
a, b = 0, 0
while num > 0:
if num >> 1 << 1 != num:
a += 1
num -= 1
else:
b += 1
... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_... |
Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.
Return the minimum number of function calls to make nums from arr.
The answer is guaranteed to fit in a 32-bit signed integer.
Example 1:
Input: nums = [1,5]
Output: 5
Explanation: Increment by 1 (second eleme... | class Solution:
def minOperations(self, nums: List[int]) -> int:
if not nums:
return 0
ans, nxt = 0, []
for num in nums:
if num & 1:
num -= 1
ans += 1
if num:
nxt.append(num // 2)
if nxt:
... | CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN NUMBER ASSIGN VAR VAR NUMBER LIST FOR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER RETURN BIN_OP VAR FUNC_CALL VAR VAR VAR |
Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.
Return the minimum number of function calls to make nums from arr.
The answer is guaranteed to fit in a 32-bit signed integer.
Example 1:
Input: nums = [1,5]
Output: 5
Explanation: Increment by 1 (second eleme... | class Solution:
def minOperations(self, nums: List[int]) -> int:
cnt = 0
if self.check(nums):
return cnt
while not self.check(nums):
for i in range(len(nums)):
cnt += nums[i] % 2
cnt += 1
self.divide2(nums)
return cnt -... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR RETURN VAR WHILE FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN BIN_OP VAR NUMBER VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER RETURN NUMBER RETURN NU... |
Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.
Return the minimum number of function calls to make nums from arr.
The answer is guaranteed to fit in a 32-bit signed integer.
Example 1:
Input: nums = [1,5]
Output: 5
Explanation: Increment by 1 (second eleme... | class Solution:
def minOperations(self, nums: List[int]) -> int:
cnt = 0
maxLen = 0
for num in nums:
num_bin = bin(num)[2:]
cnt += sum(map(int, num_bin))
maxLen = max(maxLen, len(num_bin))
return cnt + maxLen - 1 | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER VAR |
Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.
Return the minimum number of function calls to make nums from arr.
The answer is guaranteed to fit in a 32-bit signed integer.
Example 1:
Input: nums = [1,5]
Output: 5
Explanation: Increment by 1 (second eleme... | class Solution:
def minOperations(self, nums: List[int]) -> int:
arr = nums[:]
res = 0
while any(arr):
odd = sum([(x % 2 == 1) for x in arr])
if odd:
arr = [(x - x % 2) for x in arr]
res += odd
else:
arr = [... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR VAR IF VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN VAR VAR |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
if not reservedSeats:
return 2 * n
row_reservations = dict()
for reservation in reservedSeats:
row = reservation[0]
seat = reservation[1]
if seat == ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR IF VAR RETURN BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR F... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
left, right, mid = set(), set(), set()
count = 0
for row, col in reservedSeats:
if col < 6 and col > 1:
left.add(row)
if col < 10 and col > 5:
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR V... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
lookup = collections.defaultdict(list)
dic = {}
for row, seat in reservedSeats:
if row - 1 not in lookup:
data = [0] * 10
data[seat - 1] = 1
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NU... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def countAvailableSeats(self, row, taken_slots):
if row not in taken_slots:
return 2
if (
not taken_slots[row][0]
and not taken_slots[row][1]
and not taken_slots[row][2]
and not taken_slots[row][3]
):
re... | CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER VAR VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER VAR VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER VAR VAR NUMBER RETURN NUMBER VAR VAR RETURN NUMBER FUNC_DEF VAR VAR VAR VAR EXPR FUNC_C... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
seatmap = collections.defaultdict(list)
for row in reservedSeats:
seatmap[row[0]].append(row[1])
ans = 0
for row in list(seatmap.keys()):
row_arrange = [0] * 10
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER LIST NUMBER NUMB... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
total = 2 * n
dicts = {}
for k in range(len(reservedSeats)):
index = reservedSeats[k][0]
val = reservedSeats[k][1]
if index not in dicts:
dicts[i... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR LIST ... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
res = 0
rows = defaultdict(list)
for seat in reservedSeats:
rows[seat[0]].append(seat[1])
print(rows)
for row in list(rows.keys()):
seat_nums = rows[row]
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER LIST NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER AS... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
seats = sorted(reservedSeats, key=lambda x: x[0])
a = set([2, 3])
b = set([4, 5])
c = set([6, 7])
d = set([8, 9])
i = 0
ans = 0
print(seats)
seenRows... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
rowSeats = defaultdict(set)
occupiedRows = set()
freeRows = n
for seatRow, seatNum in reservedSeats:
rowSeats[seatRow].add(seatNum)
if seatRow not in occupiedRows:
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMB... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
seated = defaultdict(set)
for record in reservedSeats:
seated.setdefault(record[0], set()).add(record[1])
ans = 0
ans += (n - len(seated)) * 2
for i in seated:
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
occ = defaultdict(set)
for row, col in reservedSeats:
occ[row].add(col)
ans = 0
for row in occ:
if all(i not in occ[row] for i in range(2, 10)):
ans ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR FUNC_C... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
def isOpen(row, seat):
for i in range(seat, seat + 4):
if i in grid[row]:
return False
return True
def isClosed(row, seat):
return ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR DICT ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL ... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
reserved = dict()
for r in reservedSeats:
reserved[r[0]] = reserved.get(r[0], set())
reserved[r[0]].add(r[1])
ans = 2 * (n - len(reserved.keys()))
for _, reservation... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR LIST NUMB... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
g = defaultdict(int)
for r, s in reservedSeats:
g[r] |= {(0): 0, (1): 4, (2): 5, (3): 3, (4): 2, (5): 0}[s >> 1]
return (
sum(2 if s == 0 else 1 if s < 7 else 0 for r, s in ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER BIN_OP VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR ... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
d = {}
for r, c in reservedSeats:
if r not in d:
d[r] = [1, 1, 1]
if 2 <= c <= 5:
d[r][0] = 0
if 4 <= c <= 7:
d[r][1] = 0... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER NUMBER IF NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR ... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
reserved_in_row = defaultdict(list)
for i, j in reservedSeats:
reserved_in_row[i].append(j)
res = 2 * (n - len(reserved_in_row))
for i in reserved_in_row:
sim = [(0)... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR IF VAR NUMBER NUMBER NUMBER VAR FUNC_... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, r: List[List[int]]) -> int:
r = sorted(r)
l = [(0) for i in range(10)]
ans = 0
n_occ = 0
r.append([0, 0])
for i in range(0, len(r)):
if i == 0:
l[r[0][1] - 1] = 1
elif r[i][... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
hsh = {}
for i in reservedSeats:
row = i[0] - 1
seat = i[1] - 1
if row not in hsh:
hsh[row] = [(True) for i in range(10)]
hsh[row][seat] = Fa... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
reservedSeats.sort()
count = 2 * (reservedSeats[0][0] - 1)
row_start = 0
while row_start < len(reservedSeats):
row_end = row_start
indices = []
while (
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER I... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
ht = {}
for i, j in reservedSeats:
if not i - 1 in ht:
ht[i - 1] = [0] * 10
ht[i - 1][j - 1] = 1
ans = (n - len(ht)) * 2
for i in ht:
inc... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER NUMBER LIST NUMBE... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
res, lookup = 0, collections.defaultdict(list)
for i, j in reservedSeats:
lookup[i].append(j - 1)
for i in list(lookup.keys()):
used = False
available = [(1) for... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR LIST NUMBER NUMBER NUMBER NUMBER IF FUNC_... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
masks = {}
for row, col in reservedSeats:
masks[row] = masks.get(row, 0) + (1 << 10 - col)
cnt = 2 * (n - len(masks))
dbl_mask1, dbl_mask2 = 480, 30
mdl_mask = 120
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR B... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n, reservedSeats):
rows = {}
for r, c in reservedSeats:
if r not in rows:
rows[r] = 0
rows[r] ^= 1 << c
res = 0
p0 = 1 << 2 ^ 1 << 3 ^ 1 << 4 ^ 1 << 5
p1 = 1 << 6 ^ 1 << 7 ^ 1 << 8 ^ 1 << 9... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER BI... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
d = defaultdict(list)
prev = ans = 0
for r in reservedSeats:
d[r[0]].append(r[1])
for k in sorted(d):
if k != prev + 1:
ans += 2 * (k - prev - 1)
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR FUNC_DEF IF VAR FUNC_CAL... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
dicts = collections.defaultdict(list)
for r in reservedSeats:
dicts[r[0]].append(r[1])
res = 0
res += 2 * (n - len(dicts))
for k in list(dicts.keys()):
left ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF NUMBER VAR VAR NUMBER VAR NUM... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
reserved = set()
rows = set()
for row, col in reservedSeats:
reserved.add((row, col))
rows.add(row)
count = 2 * (n - len(rows))
for row in rows:
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR LIST NUMBER NUMBER NUMBER IF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VA... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
seat_dict = {}
all_possible_seats = [set([2, 3, 4, 5]), set([4, 5, 6, 7]), set([6, 7, 8, 9])]
for row_seat in reservedSeats:
row, seat = row_seat
temp = seat_dict.get(row, [... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR LIST FUNC_CALL VAR LIST NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR LIST NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR LIST NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBE... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reserved: List[List[int]]) -> int:
def getGroups(row):
res = 0
for group in [left, right]:
if group.isdisjoint(d[row]):
res += 1
if res >= 1:
return res
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR LIST VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER RETURN VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR LI... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
res = {}
for seat in reservedSeats:
row, seat_n = seat
if row in res:
res[row].append(seat_n)
else:
res[row] = [seat_n]
fams = 0
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR LIST NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBE... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
lookup = collections.defaultdict(list)
dic = {}
for row, seat in reservedSeats:
if row - 1 not in lookup:
data = [0] * 10
data[seat - 1] = 1
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBE... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
seats = collections.defaultdict(int)
for row, col in reservedSeats:
seats[row] = seats[row] | 1 << col - 1
res = 2 * n
for reserved in seats.values():
cnt = 0
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR STRING NUMBER NUMBER VAR BIN_OP VAR FUNC_CALL VAR STRING NUMBER NUMBER VAR BIN_O... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
all_possible_seats = [set([2, 3, 4, 5]), set([4, 5, 6, 7]), set([6, 7, 8, 9])]
seat_map = collections.defaultdict(set)
for s in reservedSeats:
seat_map[s[0]].add(s[1])
count = 0... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR LIST FUNC_CALL VAR LIST NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR LIST NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR V... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
d, ans = defaultdict(set), 0
for r, c in reservedSeats:
d[r].add(c)
absent = lambda x, s: not any([(x in s) for x in range(x, x + 4)])
for _, v in list(d.items()):
a... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER VAR BIN_OP NUMBER FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
matrix = collections.defaultdict(list)
for i in range(len(reservedSeats)):
matrix[reservedSeats[i][0]].append(reservedSeats[i][1])
res = 2 * n
for k in matrix:
cnt =... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR VAR ASSIGN VAR NUMBER IF NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER IF NUMBER VAR VAR NUMBER VAR VAR N... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
seatOcc = set()
rowsOcc = set()
for i, j in reservedSeats:
seatOcc.add((i - 1, j - 1))
rowsOcc.add(i - 1)
count = 2 * (n - len(rowsOcc))
for i in rowsOcc:
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR N... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
self.d1 = self.d2 = self.d3 = 0
reservedSeats = sorted(reservedSeats, key=lambda x: x[0])
ptr = 0
i = 0
ans = 0
while i < len(reservedSeats):
if reservedSeats[i]... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBE... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
rows = collections.defaultdict(lambda: [])
for row, col in reservedSeats:
rows[row].append(col)
ans = (n - len(rows)) * 2
def solveRow(row, pos, memo):
if pos >= 7:... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NU... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
reserved = set(tuple(spot) for spot in reservedSeats)
reserved_rows = set(spot[0] for spot in reservedSeats)
res = 0
for row in reserved_rows:
first = False
second =... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR VA... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
row_reservations = dict()
for reserve in reservedSeats:
row, col = reserve
if row not in row_reservations:
row_reservations[row] = set()
row_reservations... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR LIS... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
seats = defaultdict(set)
if len(reservedSeats) == 0:
return 2 * n
for seat in reservedSeats:
row, col = seat
seats[row].add(col)
result = 0
for i... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN BIN_OP NUMBER VAR FOR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR FUNC_CALL NUMBER NUMBER NUMBER NUMBER VAR VAR NUMBER VAR NUMBER IF FUN... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
rowseats = defaultdict(list)
for s in reservedSeats:
rowseats[s[0]].append(s[1])
subtract = 0
for _, seats in rowseats.items():
left = True
right = True
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF NUMBER VAR NUMBER ASSIGN VAR NUMBER IF NUMBER VAR NUMBER ASSIGN VAR NUMBER IF NUMBER VAR N... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reserved: List[List[int]]) -> int:
reserved.sort()
result = 2 * n
state = [1, 1, 1]
for idx, (row, col) in enumerate(reserved):
if idx > 0 and row != reserved[idx - 1][0]:
if not state[0] or not state[... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER IF VAR FUNC_CA... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
reservedSeats.sort()
matrix = {}
for i in range(len(reservedSeats)):
k = reservedSeats[i][0]
if k in matrix:
matrix[k].append(reservedSeats[i][1])
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR LIST VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER IF NUMBER VAR NUMBE... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
res, lookup = 0, collections.defaultdict(set)
for i, j in reservedSeats:
lookup[i].add(j)
for i in list(lookup.keys()):
used = False
for start, end in [(2, 6), (... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR LIST NUMBER NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR FUNC_CALL VA... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
res = 0
d = dict()
for seat in reservedSeats:
if seat[0] in d:
d[seat[0]].append(seat[1])
else:
d[seat[0]] = [seat[1]]
row = 1
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER LIST VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR N... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
res = 0
d = defaultdict(set)
for x, y in reservedSeats:
d[x - 1].add(y - 1)
for r in d.keys():
if all(x not in d[r] for x in [1, 2, 3, 4]):
res += 1
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR VAR VAR LIST NUMBER NUMBER NUMBER NUMBER VAR NUMBER FOR VAR LIST NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
BOTH, LEFT, RIGHT, MIDDLE = 0, 1, 2, 3
required = [[2, 3, 4, 5, 6, 7, 8, 9], [2, 3, 4, 5], [6, 7, 8, 9], [4, 5, 6, 7]]
fit = [2, 1, 1, 1]
res = 0
d = defaultdict(list)
for i... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUM... |
A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.
Given the array reservedSeats containing the numbers of seats already reserved, for example, reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already... | class Solution:
def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
processed = {}
seatdict = defaultdict(int)
for i in reservedSeats:
seatdict[i[0] - 1] += 2 ** i[1]
counter = 0
for i in seatdict:
seatint = seatdict[i]
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER BIN_OP ... |
We have a two dimensional matrix A where each value is 0 or 1.
A move consists of choosing any row or column, and toggling each value in that row or column: changing all 0s to 1s, and all 1s to 0s.
After making any number of moves, every row of this matrix is interpreted as a binary number, and the score of the matrix ... | class Solution:
def matrixScore(self, A: List[List[int]]) -> int:
m, n = len(A), len(A[0])
f = [0] * m
for i in range(m):
if A[i][0] == 0:
f[i] = 1
ans = 2 ** (n - 1) * m
for j in range(1, n):
cnt = sum(f[i] ^ A[i][j] for i in range(m)... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR V... |
We have a two dimensional matrix A where each value is 0 or 1.
A move consists of choosing any row or column, and toggling each value in that row or column: changing all 0s to 1s, and all 1s to 0s.
After making any number of moves, every row of this matrix is interpreted as a binary number, and the score of the matrix ... | class Solution:
def matrixScore(self, A: List[List[int]]) -> int:
R, C = len(A), len(A[0])
ans = 0
for c in range(C):
col = 0
for r in range(R):
col += A[r][c] ^ A[r][0]
ans += max(col, R - col) * 2 ** (C - 1 - c)
return ans | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR RETURN VAR VAR |
We have a two dimensional matrix A where each value is 0 or 1.
A move consists of choosing any row or column, and toggling each value in that row or column: changing all 0s to 1s, and all 1s to 0s.
After making any number of moves, every row of this matrix is interpreted as a binary number, and the score of the matrix ... | class Solution:
def matrixScore(self, A: List[List[int]]) -> int:
w = len(A[0])
h = len(A)
max_row = int(2**w) - 1
def max_col(ci):
return h * c_val(ci)
def c_val(ci):
return 2 ** (w - ci - 1)
row_sum = [sum(v * c_val(ci) for ci, v in enume... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER VAR NUMBER FUNC_DEF RETURN BIN_OP VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR F... |
We have a two dimensional matrix A where each value is 0 or 1.
A move consists of choosing any row or column, and toggling each value in that row or column: changing all 0s to 1s, and all 1s to 0s.
After making any number of moves, every row of this matrix is interpreted as a binary number, and the score of the matrix ... | class Solution:
def matrixScore(self, A: List[List[int]]) -> int:
M, N = len(A), len(A[0])
ans = (1 << N - 1) * M
for j in range(1, N):
count = sum(A[i][j] == A[i][0] for i in range(M))
ans += max(count, M - count) << N - j - 1
return ans | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMB... |
We have a two dimensional matrix A where each value is 0 or 1.
A move consists of choosing any row or column, and toggling each value in that row or column: changing all 0s to 1s, and all 1s to 0s.
After making any number of moves, every row of this matrix is interpreted as a binary number, and the score of the matrix ... | class Solution:
def matrixScore(self, A: List[List[int]]) -> int:
total = 0
for i in range(len(A)):
if A[i][0] == 0:
for j in range(len(A[0])):
A[i][j] = 1 - A[i][j]
for i in range(len(A[0])):
colZero = 0
colOne = 0
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL... |
We have a two dimensional matrix A where each value is 0 or 1.
A move consists of choosing any row or column, and toggling each value in that row or column: changing all 0s to 1s, and all 1s to 0s.
After making any number of moves, every row of this matrix is interpreted as a binary number, and the score of the matrix ... | class Solution:
def matrixScore(self, A: List[List[int]]) -> int:
def bitFlip(row):
for i, r in enumerate(row):
row[i] = 1 - r
return row
for i, row in enumerate(A):
if row[0] == 0:
A[i] = bitFlip(row)
for j in range(1, l... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR RETURN VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR... |
We have a two dimensional matrix A where each value is 0 or 1.
A move consists of choosing any row or column, and toggling each value in that row or column: changing all 0s to 1s, and all 1s to 0s.
After making any number of moves, every row of this matrix is interpreted as a binary number, and the score of the matrix ... | class Solution:
def matrixScore(self, A: List[List[int]]) -> int:
def toggle_row(row):
for j in range(len(A[0])):
if A[row][j] == 1:
A[row][j] = 0
else:
A[row][j] = 1
def toggle_col(col):
for i in rang... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ... |
We have a two dimensional matrix A where each value is 0 or 1.
A move consists of choosing any row or column, and toggling each value in that row or column: changing all 0s to 1s, and all 1s to 0s.
After making any number of moves, every row of this matrix is interpreted as a binary number, and the score of the matrix ... | class Solution:
def matrixScore(self, A: List[List[int]]) -> int:
maxsum = 0
power = len(A[0])
for row in A:
for i in range(power):
maxsum += 2 ** (power - 1 - i) * row[i]
while True:
change = False
crow = False
num = 0... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR VAR WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VA... |
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.
Example 1:
Input: s = "eleetminicoworoep"
Output: 13
Explanation: The longest substring is "leetminicowor" which contains two each of th... | class Solution:
def findTheLongestSubstring(self, s: str) -> int:
dict_vol = {"a": 0, "e": 1, "i": 2, "o": 3, "u": 4}
dict_vol = {x: (1 << y) for x, y in dict_vol.items()}
previous_seen = {(0): -1}
cur = 0
ans = 0
for i, c in enumerate(s):
if c in dict_vo... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN V... |
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.
Example 1:
Input: s = "eleetminicoworoep"
Output: 13
Explanation: The longest substring is "leetminicowor" which contains two each of th... | class Solution:
def findTheLongestSubstring(self, s: str) -> int:
vowels = "aeiou"
mask = last_mask = 0
first = [-1] + [float("inf")] * 31
last = [-1] + [float("-inf")] * 31
for i, c in enumerate(s):
if c in set(vowels):
j = vowels.index(c)
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST FUNC_CALL VAR STRING NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN... |
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.
Example 1:
Input: s = "eleetminicoworoep"
Output: 13
Explanation: The longest substring is "leetminicowor" which contains two each of th... | class Solution:
def findTheLongestSubstring(self, s):
seen = {(0): -1}
res = cur = 0
for i, c in enumerate(s):
cur ^= 1 << "aeiou".find(c) + 1 >> 1
seen.setdefault(cur, i)
res = max(res, i - seen[cur])
return res | CLASS_DEF FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL STRING VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN VAR |
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.
Example 1:
Input: s = "eleetminicoworoep"
Output: 13
Explanation: The longest substring is "leetminicowor" which contains two each of th... | class Solution:
def findTheLongestSubstring(self, s: str) -> int:
vowels = "aeiou"
helper = {(0): -1}
state = 0
res = 0
for i, ch in enumerate(s):
j = vowels.find(ch)
if j >= 0:
state ^= 1 << j
if state not in helper:
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR STRING ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN VAR VAR |
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.
Example 1:
Input: s = "eleetminicoworoep"
Output: 13
Explanation: The longest substring is "leetminicowor" which contains two each of th... | class Solution:
def findTheLongestSubstring(self, s: str) -> int:
current = [0, 0, 0, 0, 0]
def convertToInteger():
nonlocal current
binarySum = 0
for num in current:
binarySum *= 2
binarySum += num
return binarySum
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER VAR VAR RETURN VAR FUNC_DEF IF VAR STRING ASSIGN VAR NUMBER BIN_OP NUMBER VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER BIN_OP NUMBER VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER BIN_OP NUMBER VAR NUMB... |
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.
Example 1:
Input: s = "eleetminicoworoep"
Output: 13
Explanation: The longest substring is "leetminicowor" which contains two each of th... | class Solution:
def findTheLongestSubstring(self, s: str) -> int:
n, vowels, d = len(s), "aeiou", {(0): -1}
ret = cur = 0
for i, c in enumerate(s):
if c in vowels:
cur ^= 1 << vowels.index(c)
d.setdefault(cur, i)
ret = max(ret, i - d[cur])... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR STRING DICT NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN VAR VAR |
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.
Example 1:
Input: s = "eleetminicoworoep"
Output: 13
Explanation: The longest substring is "leetminicowor" which contains two each of th... | class Solution:
def findTheLongestSubstring(self, s: str) -> int:
seen = {(0, 0, 0, 0, 0): -1}
vowel = "aeiou"
count = [0] * 5
ans = 0
for i in range(len(s)):
idx = vowel.find(s[i])
if idx >= 0:
count[idx] += 1
state = tupl... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR... |
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.
Example 1:
Input: s = "eleetminicoworoep"
Output: 13
Explanation: The longest substring is "leetminicowor" which contains two each of th... | class Solution:
def findTheLongestSubstring(self, s: str) -> int:
for i in range(len(s), -1, -1):
for x in range(len(s) - i + 1):
counter = 0
temp = s[x : x + i]
for k in "aeiou":
if temp.count(k) % 2 != 0:
... | CLASS_DEF FUNC_DEF VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR FOR VAR STRING IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER RETURN VAR VAR |
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.
Example 1:
Input: s = "eleetminicoworoep"
Output: 13
Explanation: The longest substring is "leetminicowor" which contains two each of th... | class Solution:
def findTheLongestSubstring(self, s: str) -> int:
remainder_pos_dict = dict()
vowels = {"a", "e", "i", "o", "u"}
vowel_count = {ch: (0) for ch in vowels}
max_length = 0
for pos, ch in enumerate(s):
if ch in vowels:
vowel_count[ch] ... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING STRING STRING STRING STRING ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR STRING NUMBER BIN_OP VAR STRING NUMBER BIN_OP VAR STRING NUMBER BIN_OP VAR STRING NUMBER BIN_OP VAR ... |
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.
Example 1:
Input: s = "eleetminicoworoep"
Output: 13
Explanation: The longest substring is "leetminicowor" which contains two each of th... | class Solution:
def findTheLongestSubstring(self, s: str) -> int:
dic = {(0): -1}
n = 0
res = 0
voewls = {"a": 1, "e": 2, "i": 4, "o": 8, "u": 16}
for i, c in enumerate(s):
if c in voewls:
n ^= voewls[c]
if n not in dic:
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN VAR VAR |
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.
Example 1:
Input: s = "eleetminicoworoep"
Output: 13
Explanation: The longest substring is "leetminicowor" which contains two each of th... | class Solution:
def flip(self, num, pos):
if num & 2**pos:
return num - 2**pos
else:
return num + 2**pos
def findTheLongestSubstring(self, s: str) -> int:
hash = {(0, 0, 0, 0, 0): [-1]}
maxLen = 0
count = {"a": 0, "e": 0, "i": 0, "u": 0, "o": 0}
... | CLASS_DEF FUNC_DEF IF BIN_OP VAR BIN_OP NUMBER VAR RETURN BIN_OP VAR BIN_OP NUMBER VAR RETURN BIN_OP VAR BIN_OP NUMBER VAR FUNC_DEF VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL... |
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.
Example 1:
Input: s = "eleetminicoworoep"
Output: 13
Explanation: The longest substring is "leetminicowor" which contains two each of th... | class Solution:
def findTheLongestSubstring(self, s: str) -> int:
digits = {c: i for i, c in enumerate("aeiou")}
counters = [0]
for c in s:
if c in digits:
counters.append(counters[-1] ^ 1 << digits[c])
else:
counters.append(counters[-... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NU... |
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.
Example 1:
Input: s = "eleetminicoworoep"
Output: 13
Explanation: The longest substring is "leetminicowor" which contains two each of th... | class Solution:
def findTheLongestSubstring(self, S: str) -> int:
vowels = "aeiou"
seen = {(0): -1}
ans = cur = 0
for i, c in enumerate(S):
if c in vowels:
cur ^= 1 << ord(c) - 97
if cur not in seen:
seen[cur] = i
e... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR STRING ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN VAR VAR |
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.
Example 1:
Input: s = "eleetminicoworoep"
Output: 13
Explanation: The longest substring is "leetminicowor" which contains two each of th... | class Solution:
def findTheLongestSubstring(self, s: str) -> int:
mask = "00000"
table = dict()
table[mask] = -1
vowels = "aeiou"
res = 0
for i, c in enumerate(s):
for j in range(5):
if c == vowels[j]:
mask1 = list(mask... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING ... |
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.
Example 1:
Input: s = "eleetminicoworoep"
Output: 13
Explanation: The longest substring is "leetminicowor" which contains two each of th... | class Solution:
def findTheLongestSubstring(self, s: str) -> int:
d = {(0, 0, 0, 0, 0): -1}
count = [0, 0, 0, 0, 0]
pos = {"a": 0, "e": 1, "i": 2, "o": 3, "u": 4}
ans = 0
for i, char in enumerate(s):
if char in pos:
count[pos[char]] = (count[pos[c... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VA... |
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.
Example 1:
Input: s = "eleetminicoworoep"
Output: 13
Explanation: The longest substring is "leetminicowor" which contains two each of th... | class Solution:
def findTheLongestSubstring(self, s: str) -> int:
vowels, bits, dp = (
{"a", "e", "i", "o", "u"},
{"a": 0, "e": 1, "i": 2, "o": 3, "u": 4},
{(0): -1},
)
res, odds = 0, set()
for i in range(len(s)):
if s[i] in vowels:
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR VAR STRING STRING STRING STRING STRING DICT STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER DICT NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL V... |
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.
Example 1:
Input: s = "eleetminicoworoep"
Output: 13
Explanation: The longest substring is "leetminicowor" which contains two each of th... | class Solution:
def findTheLongestSubstring(self, s: str) -> int:
seen, vowel = {(0): -1}, {"a": 0, "e": 1, "i": 2, "o": 3, "u": 4}
res = curr = 0
for i, c in enumerate(s):
if c in vowel:
curr ^= 1 << vowel[c]
seen.setdefault(curr, i)
res ... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR DICT NUMBER NUMBER DICT STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN VAR VAR |
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.
Example 1:
Input: s = "eleetminicoworoep"
Output: 13
Explanation: The longest substring is "leetminicowor" which contains two each of th... | class Solution:
def findTheLongestSubstring(self, s: str) -> int:
seen = {(0): -1}
pos = {c: i for i, c in enumerate("aeiou")}
curr = res = 0
for i, c in enumerate(s):
curr ^= 1 << pos.get(c, -1) + 1 >> 1
seen.setdefault(curr, i)
res = max(res, i ... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN VAR VAR |
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.
Example 1:
Input: s = "eleetminicoworoep"
Output: 13
Explanation: The longest substring is "leetminicowor" which contains two each of th... | class Solution:
def findTheLongestSubstring(self, s: str) -> int:
for window_size in range(len(s), -1, -1):
check_range = len(s) - window_size + 1
for i in range(check_range):
check_wr = s[i : i + window_size]
right_string = True
for c... | CLASS_DEF FUNC_DEF VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR STRING IF BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR RETURN VAR RETURN NUMBER VAR |
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.
Example 1:
Input: s = "eleetminicoworoep"
Output: 13
Explanation: The longest substring is "leetminicowor" which contains two each of th... | class Solution:
def findTheLongestSubstring(self, s: str) -> int:
m = dict(a=1, e=2, i=4, o=8, u=16)
longest = 0
parity_index = {(0): -1}
parity = 0
for i, ch in enumerate(s):
parity = parity ^ m.get(ch, 0)
if parity not in parity_index:
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR VAR RETURN... |
Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.
Example 1:
Input: s = "eleetminicoworoep"
Output: 13
Explanation: The longest substring is "leetminicowor" which contains two each of th... | class Solution:
def findTheLongestSubstring(self, s: str) -> int:
seen = {(0, 0, 0, 0, 0): -1}
counts = {c: (0) for c in "aeiou"}
res = 0
for i, ch in enumerate(s):
if ch in counts:
counts[ch] += 1
key = tuple([(counts[c] % 2) for c in "aeiou"... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR STRING ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.