description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
N, skill_dict = len(req_skills), {}
for i in range(N):
skill_dict[req_skills[i]] = i
dp = [list(range(len(people))) for _ in range(1 << N)]
dp[0] ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
allneed = (1 << len(req_skills)) - 1
stoi = {}
for i, s in enumerate(req_skills):
stoi[s] = 1 << i
def serialize(arr):
res = 0
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
pmasks = []
for p in people:
mask = 0
for skill in p:
idx = req_skills.index(skill)
mask ^= 1 << idx
pmask... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR VAR RETURN LIST ASSIGN VAR NONE FOR VAR VAR FUNC_CALL VAR VAR IF BIN_... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(self, req_skills, people):
n, m = len(req_skills), len(people)
key = {v: i for i, v in enumerate(req_skills)}
dp = {(0): []}
for i, p in enumerate(people):
his_skill = 0
for skill in p:
his_skill |= 1... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT NUMBER LIST FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR F... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
l = len(req_skills)
skill_to_idx = {s: i for i, s in enumerate(req_skills)}
@functools.lru_cache(None)
def dfs(cur_skill, idx):
if cur_skill == 2... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN IF VAR FUNC_CALL VAR VAR RETURN NONE ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR ASSI... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, skills: List[str], people: List[List[str]]
) -> List[int]:
skill2idx = {skill: i for i, skill in enumerate(skills)}
for i in range(len(people)):
mask = 0
for skill in people[i]:
mask |= 1 << skill2... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR VAR RETURN IF VAR FUNC_CALL VAR VAR RETURN N... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
n = len(req_skills)
target = (1 << n) - 1
dic = {x: index for index, x in enumerate(req_skills)}
skillsMap = []
for i in people:
mask = 0
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING BIN_OP NUMBER... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
p_skills = [set() for _ in people]
for i, p in enumerate(people):
p_skills[i] = set(p)
people.sort(key=lambda x: -len(set(x) & set(req_skills)))
r... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF NUMBER LIST FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR V... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
skill_id = {skill: i for i, skill in enumerate(req_skills)}
def getSkillSetId(skills):
res = 0
for skill in skills:
if skill in skill... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP NUMBER VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN LIST NUMBER LIST IF VAR NUMBER RETURN LIST ... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
skills = []
for p in people:
cur = 0
for skill in p:
for i, req_skill in enumerate(req_skills):
if skill == req_sk... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR ... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
n = len(req_skills)
target = (1 << n) - 1
s_i = {s: i for i, s in enumerate(req_skills)}
dp = {(0): []}
for j, row in enumerate(people):
m... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT NUMBER LIST FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR BIN_OP NUMBER VAR VAR FOR VAR VAR FUNC_CALL VAR... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
n = len(req_skills)
res = {}
res[0] = set()
skill_map = {v: i for i, v in enumerate(req_skills)}
print(skill_map)
for p, skills in enumerate(p... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR ASSIGN V... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
d = {}
for i, s in enumerate(req_skills):
d[s] = i
p = []
for s in people:
c = 0
for t in s:
c |= 1 << d[t... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_DE... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
peopleLen = len(people)
skillsLen = len(req_skills)
maskFull = (1 << skillsLen) - 1
newPeople = []
for p in people:
newPeople.append(set(p... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR RETURN LIST IF VAR VAR RETURN NONE IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
N, M = len(req_skills), len(people)
NN = 1 << N
skill2id = {jj: ii for ii, jj in enumerate(req_skills)}
team = {ii: [] for ii in range(NN)}
dp = [-1] ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
dp = {(0): []}
skill_to_index = {skill: i for i, skill in enumerate(req_skills)}
for i, skills in enumerate(people):
mask = 0
for skill in ski... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR DICT NUMBER LIST ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
n, m = len(req_skills), len(people)
key = {v: i for i, v in enumerate(req_skills)}
dp = [[]] + [None] * ((1 << n) - 1)
for i, p in enumerate(people):
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST LIST BIN_OP LIST NONE BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP NUMBER VAR VAR FOR VAR FUN... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
def convertToNum(people: List[str]) -> int:
ans = 0
for skill in people:
ans |= 1 << dic[skill]
return ans
dic = {v: i f... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR FUNC_DEF VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER VAR VAR RETURN VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR LIST VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VA... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
n = len(req_skills)
target = (1 << n) - 1
skills = []
for p in people:
mask = 0
for s in p:
mask |= 1 << req_skills.in... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER VAR FU... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
m = {val: i for i, val in enumerate(req_skills)}
n = len(req_skills)
skills = [
reduce(lambda a, b: a + b, [(1 << m[s]) for s in row] or [0])
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR VAR VAR LIST NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT NUMBER LIST FOR VAR V... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
s2i = {}
for i, skill in enumerate(req_skills):
s2i[skill] = i
n = len(people)
p2n = [0] * n
for i, p in enumerate(people):
te... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VA... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
dic = {req_skills[rs]: (2**rs) for rs in range(len(req_skills))}
dp = [[] for i in range(2 ** len(req_skills))]
m_pp = []
for pp in range(len(people)):
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR LIST VAR EX... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def rec(self, rs, rdic, people, ret, rett, unis):
if len(set(unis)) == len(rs):
if len(ret) < len(rett):
return ret
if len(ret) >= len(rett):
return rett
for r, v in list(rs.items()):
if r not in set(unis):
... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR FOR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR LIST VAR VAR BIN_OP... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
skill_idx = {s: i for i, s in enumerate(req_skills)}
n = len(req_skills)
def encode(p):
res = 0
for sk in p:
res |= 1 << skil... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSI... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
n = len(req_skills)
skill_to_idx = {s: idx for idx, s in enumerate(req_skills)}
skills = []
for p in people:
mask = 0
for s in p:
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT NUMBER LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
p_skills = [set() for _ in people]
for i, p in enumerate(people):
p_skills[i] = set(p)
res = [0] * 17
def dfs(idx=0, path=[], has=set()):
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF NUMBER LIST FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP FUN... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(self, req_skills, people):
countReqSkills, memo = len(req_skills), {(0): []}
skillToIndex = {v: i for i, v in enumerate(req_skills)}
for i, ithSkills in enumerate(people):
ithSkillsBitmap = 0
for skill in ithSkills:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR DICT NUMBER LIST ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR IF VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ... |
For a given sequence of distinct non-negative integers $(b_1, b_2, \dots, b_k)$ we determine if it is good in the following way:
Consider a graph on $k$ nodes, with numbers from $b_1$ to $b_k$ written on them.
For every $i$ from $1$ to $k$: find such $j$ ($1 \le j \le k$, $j\neq i$), for which $(b_i \oplus b_j)$ is t... | import sys
input = sys.stdin.readline
def fmax(a):
if len(a) <= 2:
return len(a)
l = []
i = 1
cur = -1
ind = 0
if a[0] == 0:
l.append([0])
ind += 1
cur = 0
while ind < len(a):
if a[ind] < i:
l[cur].append(a[ind] - i // 2)
else:
... | IMPORT ASSIGN VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_... |
For a given sequence of distinct non-negative integers $(b_1, b_2, \dots, b_k)$ we determine if it is good in the following way:
Consider a graph on $k$ nodes, with numbers from $b_1$ to $b_k$ written on them.
For every $i$ from $1$ to $k$: find such $j$ ($1 \le j \le k$, $j\neq i$), for which $(b_i \oplus b_j)$ is t... | see = [1]
for i in range(41):
see.append(see[-1] * 2)
def func(arr, num):
if num == 0:
return len(arr)
if len(arr) == 1:
return 1
arr1, arr2 = [], []
for i in arr:
if i ^ see[num] == i - see[num]:
arr2.append(i)
else:
arr1.append(i)
if le... | ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR LIST LIST FOR VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CA... |
For a given sequence of distinct non-negative integers $(b_1, b_2, \dots, b_k)$ we determine if it is good in the following way:
Consider a graph on $k$ nodes, with numbers from $b_1$ to $b_k$ written on them.
For every $i$ from $1$ to $k$: find such $j$ ($1 \le j \le k$, $j\neq i$), for which $(b_i \oplus b_j)$ is t... | n = int(input())
a = list(map(int, input().split()))
def rec(s, i):
if len(s) in (0, 1, 2):
return len(s)
mask = 1 << i
a = []
b = []
for one in s:
if one & mask:
a.append(one)
else:
b.append(one)
if not a or not b:
return rec(s, i - 1)
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER NUMBER NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR I... |
For a given sequence of distinct non-negative integers $(b_1, b_2, \dots, b_k)$ we determine if it is good in the following way:
Consider a graph on $k$ nodes, with numbers from $b_1$ to $b_k$ written on them.
For every $i$ from $1$ to $k$: find such $j$ ($1 \le j \le k$, $j\neq i$), for which $(b_i \oplus b_j)$ is t... | n = int(input())
l = list(map(int, input().split()))
def fun(a):
if len(a) <= 3:
return len(a)
maxE = max(a)
if maxE == 0:
return len(a)
msb = 1
while 2 * msb <= maxE:
msb *= 2
l1 = []
l2 = []
for x in a:
if x >= msb:
l1.append(x - msb)
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR ... |
For a given sequence of distinct non-negative integers $(b_1, b_2, \dots, b_k)$ we determine if it is good in the following way:
Consider a graph on $k$ nodes, with numbers from $b_1$ to $b_k$ written on them.
For every $i$ from $1$ to $k$: find such $j$ ($1 \le j \le k$, $j\neq i$), for which $(b_i \oplus b_j)$ is t... | import sys
input = sys.stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
dp = {a[i]: (1) for i in range(n)}
for i in range(30):
next = {}
for val in dp:
if not val >> 1 in next:
next[val >> 1] = -dp[val]
elif next[val >> 1] < 0:
next[val >> 1] = ... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER ... |
For a given sequence of distinct non-negative integers $(b_1, b_2, \dots, b_k)$ we determine if it is good in the following way:
Consider a graph on $k$ nodes, with numbers from $b_1$ to $b_k$ written on them.
For every $i$ from $1$ to $k$: find such $j$ ($1 \le j \le k$, $j\neq i$), for which $(b_i \oplus b_j)$ is t... | import sys
from sys import stdin
def solve(a):
if len(a) <= 1:
return len(a)
lis = [[]]
for i in range(len(a)):
if i == 0 or a[i - 1].bit_length() == a[i].bit_length():
if a[i] != 0:
lis[-1].append(a[i] ^ 1 << a[i].bit_length() - 1)
else:
... | IMPORT FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR LIST LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NU... |
For a given sequence of distinct non-negative integers $(b_1, b_2, \dots, b_k)$ we determine if it is good in the following way:
Consider a graph on $k$ nodes, with numbers from $b_1$ to $b_k$ written on them.
For every $i$ from $1$ to $k$: find such $j$ ($1 \le j \le k$, $j\neq i$), for which $(b_i \oplus b_j)$ is t... | def main():
n = int(input())
a = [int(word) for word in input().rstrip().split()]
x = max(a)
arr = {}
for num in a:
arr[num] = 1
ans = 0
while True:
x >>= 1
dp = {}
for i in arr:
p = i >> 1
if p not in dp:
dp[p] = arr[i]... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR V... |
For a given sequence of distinct non-negative integers $(b_1, b_2, \dots, b_k)$ we determine if it is good in the following way:
Consider a graph on $k$ nodes, with numbers from $b_1$ to $b_k$ written on them.
For every $i$ from $1$ to $k$: find such $j$ ($1 \le j \le k$, $j\neq i$), for which $(b_i \oplus b_j)$ is t... | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**4)
n = int(input())
A = list(map(int, input().split()))
def calc(A):
if len(A) == 1:
return 1
C = [[] for i in range(32)]
for a in A:
if a == 0:
C[0].append(0)
else:
k = a.bit_length()
... | IMPORT ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER A... |
For a given sequence of distinct non-negative integers $(b_1, b_2, \dots, b_k)$ we determine if it is good in the following way:
Consider a graph on $k$ nodes, with numbers from $b_1$ to $b_k$ written on them.
For every $i$ from $1$ to $k$: find such $j$ ($1 \le j \le k$, $j\neq i$), for which $(b_i \oplus b_j)$ is t... | import sys
input = sys.stdin.buffer.readline
def largest_good(a):
if len(a) <= 3:
return len(a)
mx = max(a)
cutoff = 1
while 2 * cutoff <= mx:
cutoff *= 2
s0 = []
s1 = []
for i in a:
if i < cutoff:
s0.append(i)
else:
s1.append(i)
... | IMPORT ASSIGN VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR RETURN BIN_OP NUMBER FUNC_CALL VAR FUN... |
Given an array A[ ] of N integers and an integer X. In one operation, you can change the i^{th} element of the array to any integer value where 1 ≤ i ≤ N. Calculate minimum number of such operations required such that the bitwise AND of all the elements of the array is strictly greater than X.
Example 1:
Input:
N = 4, ... | class Solution:
def count(self, N, A, X):
prefix = 0
ans = N
for i in range(30, -1, -1):
if X >> i & 1 != 0:
prefix ^= 1 << i
continue
ct = 0
p = prefix ^ 1 << i
for j in range(N):
if A[j] & p ==... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR... |
Given an array A[ ] of N integers and an integer X. In one operation, you can change the i^{th} element of the array to any integer value where 1 ≤ i ≤ N. Calculate minimum number of such operations required such that the bitwise AND of all the elements of the array is strictly greater than X.
Example 1:
Input:
N = 4, ... | class Solution:
def count(self, N, A, X):
res = N
bitsetinX = 0
for i in range(31, -1, -1):
if X & 1 << i:
bitsetinX |= 1 << i
else:
mayberes = bitsetinX | 1 << i
noneedtochange = 0
for i in A:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR IF VAR STRING... |
Given an array A[ ] of N integers and an integer X. In one operation, you can change the i^{th} element of the array to any integer value where 1 ≤ i ≤ N. Calculate minimum number of such operations required such that the bitwise AND of all the elements of the array is strictly greater than X.
Example 1:
Input:
N = 4, ... | class Solution:
def count(self, N, A, X):
m = A[0]
for i in range(1, N):
m &= A[i]
ans = N
for i in range(32):
if 1 << i | m > X:
c = 0
for x in A:
if x & 1 << i == 0:
c += 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CAL... |
Given an array A[ ] of N integers and an integer X. In one operation, you can change the i^{th} element of the array to any integer value where 1 ≤ i ≤ N. Calculate minimum number of such operations required such that the bitwise AND of all the elements of the array is strictly greater than X.
Example 1:
Input:
N = 4, ... | class Solution:
def count(self, n, l, x):
def fun(t):
c = 0
for i in l:
if t & i != t:
c += 1
return c
maxv = max(l)
ans = n
for i in range(maxv + 1):
a = 1 << i
t = x + a - x % a
... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR... |
Given an array A[ ] of N integers and an integer X. In one operation, you can change the i^{th} element of the array to any integer value where 1 ≤ i ≤ N. Calculate minimum number of such operations required such that the bitwise AND of all the elements of the array is strictly greater than X.
Example 1:
Input:
N = 4, ... | class Solution:
def count(self, N, A, X):
res, bitset = N, 0
for i in range(32, -1, -1):
if X & 1 << i > 0:
bitset |= 1 << i
else:
count = 0
temp = bitset | 1 << i
for num in A:
if num & temp... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR FOR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR |
Given an array A[ ] of N integers and an integer X. In one operation, you can change the i^{th} element of the array to any integer value where 1 ≤ i ≤ N. Calculate minimum number of such operations required such that the bitwise AND of all the elements of the array is strictly greater than X.
Example 1:
Input:
N = 4, ... | class Solution:
def count(self, N, A, X):
ans = 10**9 + 9
cur_xor = 0
for i in range(31, -1, -1):
if X & 1 << i:
cur_xor = cur_xor | 1 << i
else:
temp = cur_xor | 1 << i
cnt = 0
for i in range(0, N):
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR ASSIG... |
Chef has a tree consisting of N nodes, rooted at node 1. Every node of this tree can be assigned a binary value (0 or 1). Initially, every node is assigned 0.
We define AND-value of a set of nodes as the [bitwise AND] of all the values of the nodes in it.
An edge in the tree is called good, if after removing this ed... | def dfs(curr, adj, par, child):
for elem in adj[curr]:
if par[elem] != -1:
continue
par[elem] = curr
child[curr].append(elem)
dfs(elem, adj, par, child)
for i in range(int(input())):
n = int(input())
val = [0] * n
adj = []
child = []
for j in range(n... | FUNC_DEF FOR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL ... |
Chef has a tree consisting of N nodes, rooted at node 1. Every node of this tree can be assigned a binary value (0 or 1). Initially, every node is assigned 0.
We define AND-value of a set of nodes as the [bitwise AND] of all the values of the nodes in it.
An edge in the tree is called good, if after removing this ed... | def dfs(curr, ar, ct, tree):
count = 0
for i in ar[curr]:
if tree[curr] == i:
continue
tree[i] = curr
count += dfs(i, ar, ct, tree)
ct[curr] = count
return 1
t = int(input())
for _ in range(t):
n = int(input())
l = [[] for _ in range(n + 1)]
for i in ran... | FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VA... |
Chef has a tree consisting of N nodes, rooted at node 1. Every node of this tree can be assigned a binary value (0 or 1). Initially, every node is assigned 0.
We define AND-value of a set of nodes as the [bitwise AND] of all the values of the nodes in it.
An edge in the tree is called good, if after removing this ed... | def order(parent, children, thisdict, visited, element, par):
if visited[element] == True:
return
visited[element] = True
parent[element] = par
if par != -1:
children[par].append(element)
for i in thisdict[element]:
if visited[i] == False:
order(parent, children, ... | FUNC_DEF IF VAR VAR NUMBER RETURN ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER VAR ... |
Chef has a tree consisting of N nodes, rooted at node 1. Every node of this tree can be assigned a binary value (0 or 1). Initially, every node is assigned 0.
We define AND-value of a set of nodes as the [bitwise AND] of all the values of the nodes in it.
An edge in the tree is called good, if after removing this ed... | for _ in range(int(input())):
n = int(input())
graph = [dict() for _ in range(n + 1)]
cnt = [0] * (n + 1)
cnt[1] = 1
graph[0][1] = True
graph[1][0] = True
for i in range(n - 1):
u, v = map(int, input().split())
cnt[u] += 1
cnt[v] += 1
graph[u][v] = True
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR ... |
Chef has a tree consisting of N nodes, rooted at node 1. Every node of this tree can be assigned a binary value (0 or 1). Initially, every node is assigned 0.
We define AND-value of a set of nodes as the [bitwise AND] of all the values of the nodes in it.
An edge in the tree is called good, if after removing this ed... | T = int(input())
for _ in range(T):
V = int(input())
val = {(i + 1): (0) for i in range(V)}
E = []
P = {(i + 1): (-1) for i in range(V)}
C = {(i + 1): [] for i in range(V)}
A = {(i + 1): [] for i in range(V)}
for i in range(V - 1):
u, v = (int(j) for j in input().split())
E.a... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER LIST VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP 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:
n = len(nums)
done = [0] * n
ans = 0
while nums != done:
for i, x in enumerate(nums):
if x % 2:
nums[i] -= 1
ans += 1
if nums != done:
... | 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 FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR FOR VAR 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:
count = 0
while True:
op = False
zeroes = 0
for i in range(len(nums)):
if nums[i] % 2 != 0:
count += 1
nums[i] -= 1
for i in range... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF V... |
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:
valid = {(0): 0}
for i in range(31):
valid[2**i] = i
ans = 0
max_multi_step = float("-inf")
for i in range(len(nums)):
if nums[i] > 0:
ans += 1
else:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR IF BIN_OP VAR VAR NUMBER 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:
def count_ops(x: int) -> int:
if x == 0:
return 0, 0
elif x == 1:
return 1, 0
elif x % 2 == 0:
add, mul = count_ops(x // 2)
return add, mul +... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF VAR IF VAR NUMBER RETURN NUMBER NUMBER IF VAR NUMBER RETURN NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER 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:
length = len(nums)
def check_all_zeros(arr):
for ele in arr:
if ele != 0:
return False
return True
def divide_by_2(arr):
return list([(x / 2) for x in a... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF FOR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP 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:
ans = 0
n = len(nums)
s = sum(nums)
while s != 0:
nums_2 = [(num % 2) for num in nums]
diff = sum(nums_2)
if diff == 0:
nums = [(num // 2) for num in nums]
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CA... |
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:
next_nums = [0] * len(nums)
all_zeros = True
for i, x in enumerate(nums):
if x == 0:
continue
if x % 2 != 0:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN 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:
adds = []
muls = []
for idx, num in enumerate(nums):
adds.append(0)
muls.append(0)
while num > 0:
if num % 2 == 1:
adds[idx] += 1
num ... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER RETURN BIN_OP FUNC_CALL VAR 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:
ret = 0
change = 0
while sum(nums):
change = 0
for i in range(len(nums)):
if nums[i] % 2:
ret += 1
nums[i] -= 1
change = 1
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER RETU... |
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
onesCount = 0
aboveOneIdxs = []
for idx, n in enumerate(nums):
if n == 1:
onesCount += 1
elif n > 1:
aboveOneIdxs.append(idx)
while onesCount + ... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER 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_1(self, nums: List[int]) -> int:
ops = 0
while not all(n == 0 for n in nums):
for i, n in enumerate(nums):
if n % 2 != 0:
nums[i] = n - 1
ops += 1
if all(n == 0 for n in nums):
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN VAR VAR FUNC_DEF VAR VAR ASSIGN 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:
ones = 0
maxLength = 0
for x in nums:
x = bin(x)[2:]
maxLength = max(maxLength, len(x))
ones += x.count("1")
print((ones, maxLength - 1))
return ones + maxLength - 1 | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER 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:
valid = {(0): 0}
for i in range(31):
valid[2**i] = i
ans = 0
for i in range(len(nums)):
if nums[i] > 0:
ans += 1
max_val = float("-inf")
need_step = [0] * len(num... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CAL... |
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 any(num != 0 for num in nums):
odd = 0
for idx, num in enumerate(nums):
if num & 1:
nums[idx] -= 1
odd += 1
ans += 1
... | 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 VAR NUMBER VAR NUMBER VAR NUMBER IF VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP 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, A: List[int]) -> int:
r = 0
while A != [(0) for i in A]:
odd = 0
for i in range(len(A)):
if A[i] % 2 == 1:
A[i] = A[i] - 1
odd += 1
if odd == 0:
A = [(... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER 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 minOperations0(self, nums: List[int]) -> int:
l = len(nums)
ans = 0
def turnEven():
nonlocal ans
for i in range(l):
if nums[i] % 2 == 1:
nums[i] -= 1
ans += 1
def countZero():
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER RETURN VAR WHILE NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR RETURN VAR FOR VAR FUNC_C... |
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:
zeroIndexes = set()
result = 0
isEven = False
while len(zeroIndexes) != len(nums):
if isEven:
for i in range(len(nums)):
nums[i] >>= 1
result += 1
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMB... |
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 True:
for i, x in enumerate(nums):
if x & 1:
result += 1
nums[i] -= 1
if all(x == 0 for x in nums):
return result
... | 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 VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR RETURN VAR FOR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER 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:
maxTwos = 0
ones = 0
for num in nums:
count, left = self.getCount(num)
maxTwos = max(maxTwos, count)
ones += left
return ones + maxTwos
def getCount(self, num):
count = ... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER 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:
ans = 0
n = len(nums)
while True:
ok = False
flag = True
for i in range(n):
if nums[i] & 1:
ans += 1
nums[i] -= 1
if n... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN 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:
def all_zeros(nums):
for num in nums:
if num != 0:
return False
return True
def to_all_evens(nums):
cnt = 0
for i in range(len(nums)):
... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF FOR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER RETURN VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN 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:
op = 0
while len(nums) > 0:
for i in range(len(nums)):
if nums[i] % 2 == 1:
nums[i] -= 1
op += 1
nums = list(filter(lambda x: x != 0, nums))
i... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RE... |
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:
mx = 1
ops = 0
for nm in nums:
bt = 0
while nm > 0:
ops += nm & 1
bt += 1
nm = nm >> 1
mx = max(mx, bt)
return ops + mx - 1 | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR 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 makeHalf(self, a):
for i in range(len(a)):
a[i] //= 2
def makeEven(self, a):
c = 0
for i in range(len(a)):
if a[i] % 2 == 0:
continue
else:
a[i] -= 1
c += 1
return c
def... | CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR N... |
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, a: List[int]) -> int:
ans = 0
mx = 0
for x in a:
cnt = 0
while x:
if x % 2:
ans += 1
cnt += 1
x //= 2
mx = max(mx, cnt)
return max(ans + mx... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER 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:
res = 0
sum1 = 1
while sum1 != 0:
sum1 = 0
for ii, i in enumerate(nums):
if i % 2 != 0:
nums[ii] -= 1
res += 1
nums[ii] = nums[ii]... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER RETURN BIN_OP 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:
ops = 0
while not all(n == 0 for n in nums):
for i, n in enumerate(nums):
if n % 2 != 0:
nums[i] = n - 1
ops += 1
if all(n == 0 for n in nums):
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR 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... | class Solution:
def minOperations(self, nums: List[int]) -> int:
n = len(nums)
res = 0
max_zero = 0
for i in range(len(nums)):
zero, one = Solution.parse(nums[i])
res += one
max_zero = max(max_zero, zero)
res += max_zero
return res... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER 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:
even_num = []
odd_num = []
zero_num = []
def category(n, zero_num, even_num, odd_num):
if n == 0:
zero_num.append(n)
elif n % 2 == 0:
even_num.append(n)
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST IF... |
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:
nums.sort()
result = 0
multiple = 0
last = 0
def find(mx):
nonlocal last
if mx <= 1:
return mx
if mx % 2 == 1:
return find(mx - 1) + 1
... | CLASS_DEF FUNC_DEF VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN VAR IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL V... |
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, A):
steps, n = 0, len(A)
while True:
zeros = 0
for i in range(n):
if A[i] % 2 > 0:
A[i] -= 1
steps += 1
if A[i] == 0:
zeros += 1
if... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR WHILE NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER RETURN 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:
inc, mult = 0, 0
for i in nums:
if i:
a, b = self.getRes(i)
inc += a
mult = max(mult, b)
return inc + mult
def getRes(self, n):
inc, mult = 0, 0
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER WHILE VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER 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, t: List[int]) -> int:
n = len(t)
ans = 0
while 1:
z = 0
i = 0
while i < n:
if t[i] % 2:
break
elif t[i] == 0:
z += 1
i += 1
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR RETURN VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER FOR VAR FUN... |
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... | masks = [1431655765, 858993459, 252645135, 16711935, 65535]
class Solution:
def minOperations(self, nums: List[int]) -> int:
totOddRem = 0
maxX = nums[0]
for x in nums:
if x == 1:
totOddRem += 1
else:
xCopy = x
for p,... | ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN 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:
ans = 0
shift = 0
for k in nums:
strk = bin(k)[2:]
ans += strk.count("1")
shift = max(shift, len(strk) - 1)
return ans + shift | 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 STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN BIN_OP 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 Solution1:
def minOperations(self, nums: List[int]) -> int:
twos = 0
ones = 0
for n in nums:
mul = 0
while n:
if n % 2:
n -= 1
ones += 1
else:
n //= 2
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR VAR VAR CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN V... |
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
nz = 0
for num in nums:
if num > 0:
nz += 1
while nz > 0:
div2 = False
for i in range(len(nums)):
if nums[i] % 2 == 1:
num... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER WHILE 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 VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER IF 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:
def get_op(n):
op_0 = 0
op_1 = 0
while n != 0:
if n % 2 == 0:
op_1 += 1
n = n // 2
else:
op_0 += 1
... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETU... |
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 = [0] * len(nums)
count = 0
while nums != arr:
check = True
for x in nums:
if x % 2 != 0:
check = False
if check == True:
count += 1
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL 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):
add_operations = {}
result = 0
max_m = 0
for i in nums:
current = i
if current in add_operations:
result += add_operations[current]
else:
add_amount = 0
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN BIN... |
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:
odds: List[int] = [n for n in nums if n % 2 == 1]
evens: Set[int] = [n for n in nums if n != 0 and n % 2 == 0]
new: List[int] = []
n: int = 0
n_ops: int = 0
while len(odds) > 0 or len(evens) > 0:
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR LIST VAR VAR NUMBER VAR VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER IF 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:
count = 0
double = 0
for i in range(len(nums)):
cd = 0
while nums[i] > 0:
if nums[i] % 2 == 1:
count += 1
cd += 1
nums[i] //= 2
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR 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:
num_operations = 0
odd = True
even = False
while odd or even:
if odd:
for i in range(len(nums)):
if nums[i] != 0:
if nums[i] % 2:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL 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:
counter = 0
while 1:
temp_counter = 0
bigger_than_zero = 0
for i in range(len(nums)):
if nums[i] % 2 == 1:
temp_counter += 1
nums[i] -= 1
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER RETURN VAR ASSIGN VAR NUMBER WHILE VAR VAR N... |
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 helper(num):
if num in self.dic:
return self.dic[num]
n = num
count, even = 0, 0
while n != 0:
if n % 2 == 1:
n -= 1
else... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF VAR VAR RETURN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR RETURN VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER DICT FOR VAR VAR ASSIGN VAR 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:
mul = [(0) for i in range(len(nums))]
inc = [(0) for i in range(len(nums))]
for i in range(len(nums)):
while nums[i] != 0:
if nums[i] % 2 == 1:
inc[i] += 1
nu... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER RETURN BIN... |
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:
zeros = 0
for i in range(len(nums)):
if nums[i] % 2 == 0:
continue
else:
nums[i] -= 1
count += 1... | 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 NUMBER VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR FUNC_CALL 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:
def proc(nums):
cnt = 0
for i in range(len(nums)):
if nums[i] % 2 > 0:
nums[i] -= 1
cnt += 1
if cnt == 0:
for i in range(len(nums)):
... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF 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 NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL 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:
if max(nums) == 0:
return 0
return sum(map(lambda x: bin(x).count("1"), nums)) + int(log2(max(nums))) | CLASS_DEF FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR FUNC_CALL 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:
def calculate(num):
temp1 = 0
temp2 = 0
while num:
if num % 2:
temp1 += 1
num -= 1
else:
temp2 += 1
... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN BIN_OP... |
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:
totOddRem = 0
max2Power = 0
for x in nums:
pow2 = 0
while True:
totOddRem += x & 1
if x > 1:
pow2 += 1
x >>= 1
els... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER WHILE NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN BIN_OP 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:
if not nums or sum(nums) == 0:
return 0
cnt = 0
while sum(nums) != 0:
if all(num % 2 == 0 for num in nums):
cnt += 1
for i in range(len(nums)):
nums[i... | CLASS_DEF FUNC_DEF VAR VAR IF VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER 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:
def calc(num):
tmp = 1
ans = [0, 0]
count = 0
while tmp <= num:
if tmp & num != 0:
ans[0] += 1
count += 1
tmp <<= 1
... | CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.