description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def hpartition(self, arr, left, right): pivot = arr[left] while True: while arr[left] < pivot: left += 1 while arr[right] > pivot: right -= 1 if left >= right: return left arr[left], arr[...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR WHILE NUMBER WHILE VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR NUMBER IF VAR VAR RETURN VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_D...
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): order = {"!": 0, "#": 1, "$": 2, "%": 3, "&": 4, "*": 5, "@": 6, "^": 7, "~": 8} nuts.sort(key=lambda x: order[x]) bolts.sort(key=lambda x: order[x]) return nuts, bolts
CLASS_DEF FUNC_DEF ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR VAR
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): d = { "!": 0, "#": 1, "$": 2, "%": 3, "&": 4, "*": 5, "@": 6, "^": 7, "~": 8, ".": 9, } d1 = { (0): "!", ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER STRING STRING STRING STRING STRING STRING STRING STRING STR...
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): s = ["!", "#", "$", "%", "&", "*", "@", "^", "~"] for i in s: if i in nuts: nuts.append(i) nuts.remove(i) bolts.append(i) bolts.remove(i)
CLASS_DEF FUNC_DEF ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): nuts.sort() bolts.sort() ans = [] for i in range(n): ans.append([nuts[i], bolts[i]]) return ans
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR RETURN VAR
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): lst = list("!#$%&*@^~") k = 0 for i in lst: if i in bolts: nuts[k] = i k += 1 k = 0 for i in nuts: bolts[k] = i k += 1
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): d = {"!": 0, "#": 1, "$": 2, "%": 3, "&": 4, "*": 5, "@": 6, "^": 7, "~": 8} d_ = { (0): "!", (1): "#", (2): "$", (3): "%", (4): "&", (5): "*", (6): "@", ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER STRING STRING STRING STRING STRING STRING STRING STRING STRING FOR VAR FUNC_CALL...
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, a, b, n): temp = [] for i in range(len(b)): temp.append(ord(b[i])) temp.sort() for i in range(len(temp)): a[i] = b[i] = chr(temp[i])
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def get_key(self, val, my_dict): for key, value in my_dict.items(): if val == value: return key def matchPairs(self, nuts, bolts, n): ele_order = { "!": 0, "#": 1, "$": 2, "%": 3, "&": 4, ...
CLASS_DEF FUNC_DEF FOR VAR VAR FUNC_CALL VAR IF VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR EXP...
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): st = "!#$%&*@^~" d = {st[x]: x for x in range(len(st))} nuts.sort(key=lambda s: d[s]) bolts.sort(key=lambda s: d[s])
CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): ord = ["!", "#", "$", "%", "&", "*", "@", "^", "~"] matcher = dict() for i in nuts: matcher[i] = 1 for j in bolts: matcher[j] += 1 res = [] for o in ord: if matcher.get(o) == 2:...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL ...
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): l = ["!", "#", "$", "%", "&", "*", "@", "^", "~"] p = 0 x = [] for i in range(len(l)): if l[p] in nuts and l[p] in bolts: x.append(l[p]) p = p + 1 for i in range(len(nuts)): ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR AS...
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): nuts_hash = {} for i, v in enumerate(nuts): nuts_hash[v] = i bolts_hash = {} for i, v in enumerate(bolts): bolts_hash[v] = i i = 0 for c in "!#$%&*@^~": if nuts_hash.get(c) != N...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR STRING IF FUNC_CALL VAR VAR NONE FUNC_CALL VAR VAR NONE ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): a = {"!": 0, "#": 1, "$": 2, "%": 3, "&": 4, "*": 5, "@": 6, "^": 7, "~": 8} s = { (0): "!", (1): "#", (2): "$", (3): "%", (4): "&", (5): "*", (6): "@", ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST A...
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): return self.matchPairsUtil(nuts, bolts, 0, n - 1) def matchPairsUtil(self, nuts, bolts, start, end): if start < end: pivot = self.partetion(nuts, start, end, bolts[end]) self.partetion(bolts, start, end, nuts[pivot])...
CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE ...
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): order = ["!", "#", "$", "%", "&", "*", "@", "^", "~"] hnuts = {i: j for i in order for j in [0] * 9} for ele in nuts: hnuts[ele] = 1 res = [] for i in order: if hnuts[i]: res.append...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR VAR VAR VAR VAR VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): stg = "!#$%&*@^~" dic = {} for i in range(len(stg)): dic[stg[i]] = i nuts.sort(key=lambda x: dic[x]) bolts.sort(key=lambda x: dic[x])
CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): ref = ["!", "#", "$", "%", "&", "*", "@", "^", "~"] ans = [] for val in ref: if val in nuts: ans.append(val) for i in range(len(nuts)): nuts.pop() for val in ans: nuts.a...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR...
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): l = ["!", "#", "$", "%", "&", "*", "@", "^", "~"] nd = {} bd = {} for i in nuts: if i not in nd: nd[i] = 1 else: nd[i] += 1 for i in bolts: if i not in b...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VA...
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): nd, bd = {}, {} for n in nuts: nd[n] = True for b in bolts: bd[b] = True nuts.clear() bolts.clear() a = ["!", "#", "$", "%", "&", "*", "@", "^", "~"] for i in a: if nd.g...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR DICT DICT FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING FOR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VA...
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): s = "!#$%&*@^~" f = {} for i in nuts: f[i] = f.get(i, 0) + 1 j = 0 for i in s: for k in range(f.get(i, 0)): nuts[j] = i bolts[j] = i j += 1
CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): res = ["!", "#", "$", "%", "&", "*", "@", "^", "~"] ans = [0] * len(res) for i in nuts: ans[res.index(i)] = 1 ind = 0 for i in range(len(ans)): if ans[i]: nuts[ind] = res[i] ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): arr = ["!", "#", "$", "%", "&", "*", "@", "^", "~"] ans1 = [] for i in arr: if i in nuts: ans1.append(i) for i in range(len(nuts)): nuts[i] = ans1[i] bolts[i] = ans1[i]
CLASS_DEF FUNC_DEF ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): d = {"!": 1, "#": 2, "$": 3, "%": 4, "&": 5, "*": 6, "@": 7, "^": 8, "~": 9} x = [[] for i in range(1, 10)] for i in nuts: x[d[i] - 1].append(i) result1 = [] for i in x: if len(i) > 0: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR NUMBE...
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): nuts.sort() bolts.sort() i, j = 0, 0 list1 = [] k, l = 0, 0 while i < n and j < n: if nuts[i] == bolts[j]: nuts[k] = nuts[i] k += 1 bolts[l] = bolts[j] ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBE...
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bots, n): a = "!#$%&*@^~" h = {"!": 1, "#": 2, "$": 3, "%": 4, "&": 5, "*": 6, "@": 7, "^": 8, "~": 9} for i in range(n): nuts[i] = h[nuts[i]] bots[i] = h[bots[i]] nuts.sort() bots.sort() for i in ran...
CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR V...
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): o = "!#$%&*@^~" dic = {} for i in range(len(o)): dic[o[i]] = i def helper(s, e, pi, arr): i = s while s < e: if dic[arr[s]] < pi: arr[s], arr[i] = arr[i], a...
CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_DEF ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VA...
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): d = {} for i in nuts: d[ord(i)] = i l = list(d.keys()) l.sort() nuts.clear() for i in l: nuts.append(d[i]) bolts.clear() bolts.extend(nuts)
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: mapping = {"!": 1, "#": 2, "$": 3, "%": 4, "&": 5, "*": 6, "@": 7, "^": 8, "~": 9} def merge_arr(self, low, mid, high, arr): l = low h = mid + 1 k = 0 ans = list() while l <= mid and h <= high: if self.mapping[arr[l]] < self.mapping[arr[h]]: ...
CLASS_DEF ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ...
Given a set of N nuts of different sizes and N bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently. Comparison of a nut to another nut or a bolt to another bolt is not allowed. It means nut can only be compared with bolt and bolt can only be compared with nut to...
class Solution: def matchPairs(self, nuts, bolts, n): d = {"!": 1, "#": 2, "$": 3, "%": 4, "&": 5, "*": 6, "@": 7, "^": 8, "~": 9} for i in range(len(nuts) - 1): for j in range(len(nuts) - 1 - i): if nuts[j] > nuts[j + 1]: nuts[j], nuts[j + 1] = nuts[...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN ...
Given an array Arr[] of size N. Find the number of subarrays whose sum is an even number. Example 1: Input: N = 6 Arr[] = {1, 2, 2, 3, 4, 1} Output: 9 Explanation: The array {1, 2, 2, 3, 4, 1} has 9 such possible subarrays. These are- {1, 2, 2, 3} Sum = 8 {1, 2, 2, 3, 4} Sum = 12 {2} ...
class Solution: def countEvenSum(self, arr, n): even, odd = 0, 0 s = 0 ans = 0 for i in arr: s += i if s % 2 == 0: even += 1 else: odd += 1 ans = even * (even - 1) // 2 + odd * (odd - 1) // 2 + even ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR RETURN VAR
Given an array Arr[] of size N. Find the number of subarrays whose sum is an even number. Example 1: Input: N = 6 Arr[] = {1, 2, 2, 3, 4, 1} Output: 9 Explanation: The array {1, 2, 2, 3, 4, 1} has 9 such possible subarrays. These are- {1, 2, 2, 3} Sum = 8 {1, 2, 2, 3, 4} Sum = 12 {2} ...
class Solution: def countEvenSum(self, arr, n): odd = 0 even = 0 summa = 0 for item in arr: summa += item odd += summa % 2 even += summa % 2 == 0 count = even summa = 0 for item in arr: summa += item ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR VAR RETURN VAR
Given an array Arr[] of size N. Find the number of subarrays whose sum is an even number. Example 1: Input: N = 6 Arr[] = {1, 2, 2, 3, 4, 1} Output: 9 Explanation: The array {1, 2, 2, 3, 4, 1} has 9 such possible subarrays. These are- {1, 2, 2, 3} Sum = 8 {1, 2, 2, 3, 4} Sum = 12 {2} ...
class Solution: def countEvenSum(self, arr, n): eve = odd = s = out = 0 for i in range(n): s += arr[i] if s % 2 == 0: out += 1 + eve eve += 1 else: out += odd odd += 1 return out
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER RETURN VAR
Given an array Arr[] of size N. Find the number of subarrays whose sum is an even number. Example 1: Input: N = 6 Arr[] = {1, 2, 2, 3, 4, 1} Output: 9 Explanation: The array {1, 2, 2, 3, 4, 1} has 9 such possible subarrays. These are- {1, 2, 2, 3} Sum = 8 {1, 2, 2, 3, 4} Sum = 12 {2} ...
class Solution: def countEvenSum(self, arr, n): even = 0 odd = 0 sum = 0 r = 0 for i in range(n): sum += arr[i] if sum % 2 != 0: r += odd odd = odd + 1 else: r += even + 1 eve...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
Given an array Arr[] of size N. Find the number of subarrays whose sum is an even number. Example 1: Input: N = 6 Arr[] = {1, 2, 2, 3, 4, 1} Output: 9 Explanation: The array {1, 2, 2, 3, 4, 1} has 9 such possible subarrays. These are- {1, 2, 2, 3} Sum = 8 {1, 2, 2, 3, 4} Sum = 12 {2} ...
class Solution: def countEvenSum(self, arr, n): sum = 0 t = 0 for i in reversed(range(n)): if arr[i] % 2 == 1: t = n - i - 1 - t else: t = t + 1 sum = sum + t return sum if __name__ == "__main__": tc = int(inp...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN...
Given an array Arr[] of size N. Find the number of subarrays whose sum is an even number. Example 1: Input: N = 6 Arr[] = {1, 2, 2, 3, 4, 1} Output: 9 Explanation: The array {1, 2, 2, 3, 4, 1} has 9 such possible subarrays. These are- {1, 2, 2, 3} Sum = 8 {1, 2, 2, 3, 4} Sum = 12 {2} ...
class Solution: def countEvenSum(self, arr, n): s = 0 res = 0 for i in range(n - 1, -1, -1): if arr[i] & 1: s = n - i - 1 - s else: s = s + 1 res = res + s return res
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR
Given an array Arr[] of size N. Find the number of subarrays whose sum is an even number. Example 1: Input: N = 6 Arr[] = {1, 2, 2, 3, 4, 1} Output: 9 Explanation: The array {1, 2, 2, 3, 4, 1} has 9 such possible subarrays. These are- {1, 2, 2, 3} Sum = 8 {1, 2, 2, 3, 4} Sum = 12 {2} ...
class Solution: def countEvenSum(self, arr, n): o, e, c = 0, 0, 0 for i in range(n): if arr[i] % 2 == 0: o = o e += 1 else: t = e e = o o = t + 1 c += e return c
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR
Given an array Arr[] of size N. Find the number of subarrays whose sum is an even number. Example 1: Input: N = 6 Arr[] = {1, 2, 2, 3, 4, 1} Output: 9 Explanation: The array {1, 2, 2, 3, 4, 1} has 9 such possible subarrays. These are- {1, 2, 2, 3} Sum = 8 {1, 2, 2, 3, 4} Sum = 12 {2} ...
class Solution: def countEvenSum(self, arr, n): ce, co = 0, 0 s = 0 for x in arr: if x % 2 == 0: ce += 1 else: old_co = co co = ce + 1 ce = old_co s += ce return s
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR RETURN VAR
Given an array Arr[] of size N. Find the number of subarrays whose sum is an even number. Example 1: Input: N = 6 Arr[] = {1, 2, 2, 3, 4, 1} Output: 9 Explanation: The array {1, 2, 2, 3, 4, 1} has 9 such possible subarrays. These are- {1, 2, 2, 3} Sum = 8 {1, 2, 2, 3, 4} Sum = 12 {2} ...
class Solution: def countEvenSum(self, arr, n): temp = [1, 0] result = 0 sum = 0 for i in range(n): sum = ((sum + arr[i]) % 2 + 2) % 2 temp[sum] += 1 result = result + temp[0] * (temp[0] - 1) // 2 result = result + temp[1] * (temp[1] - 1) // 2...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUM...
Given an array Arr[] of size N. Find the number of subarrays whose sum is an even number. Example 1: Input: N = 6 Arr[] = {1, 2, 2, 3, 4, 1} Output: 9 Explanation: The array {1, 2, 2, 3, 4, 1} has 9 such possible subarrays. These are- {1, 2, 2, 3} Sum = 8 {1, 2, 2, 3, 4} Sum = 12 {2} ...
class Solution: def countEvenSum(self, arr, n): cnt = [0, 0] ans = 0 for a in arr: if a % 2 == 0: ans += cnt[0] + 1 cnt[0] += 1 else: ans += cnt[1] cnt[0], cnt[1] = cnt[1], cnt[0] + 1 return ans
CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN VAR
Given an array Arr[] of size N. Find the number of subarrays whose sum is an even number. Example 1: Input: N = 6 Arr[] = {1, 2, 2, 3, 4, 1} Output: 9 Explanation: The array {1, 2, 2, 3, 4, 1} has 9 such possible subarrays. These are- {1, 2, 2, 3} Sum = 8 {1, 2, 2, 3, 4} Sum = 12 {2} ...
class Solution: def countEvenSum(self, arr, n): csm = odd = ev = 0 for i in arr: csm += i if csm & 1: odd += 1 else: ev += 1 ans = n * (n + 1) // 2 - odd * (1 + ev) return ans
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER FOR VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP NUMBER VAR RETURN VAR
Given an array Arr[] of size N. Find the number of subarrays whose sum is an even number. Example 1: Input: N = 6 Arr[] = {1, 2, 2, 3, 4, 1} Output: 9 Explanation: The array {1, 2, 2, 3, 4, 1} has 9 such possible subarrays. These are- {1, 2, 2, 3} Sum = 8 {1, 2, 2, 3, 4} Sum = 12 {2} ...
class Solution: def countEvenSum(self, arr, n): e = 0 o = 0 s = 0 ans = 0 for i in range(n): s += arr[i] if s % 2 == 0: ans += 1 + e e += 1 else: ans += o o += 1 retur...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER RETURN VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_...
Given an array Arr[] of size N. Find the number of subarrays whose sum is an even number. Example 1: Input: N = 6 Arr[] = {1, 2, 2, 3, 4, 1} Output: 9 Explanation: The array {1, 2, 2, 3, 4, 1} has 9 such possible subarrays. These are- {1, 2, 2, 3} Sum = 8 {1, 2, 2, 3, 4} Sum = 12 {2} ...
class Solution: def countEvenSum(self, arr, n): ans = 0 sm = 0 eve, odd = 0, 0 for i in range(n): sm += arr[i] if sm % 2 != 0: ans += odd odd += 1 else: ans += eve + 1 eve += 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR
Given an array Arr[] of size N. Find the number of subarrays whose sum is an even number. Example 1: Input: N = 6 Arr[] = {1, 2, 2, 3, 4, 1} Output: 9 Explanation: The array {1, 2, 2, 3, 4, 1} has 9 such possible subarrays. These are- {1, 2, 2, 3} Sum = 8 {1, 2, 2, 3, 4} Sum = 12 {2} ...
class Solution: def countEvenSum(self, arr, n): sub_parity = [0, 0] total_even = 0 odd = 0 even = 0 for i in range(n): if arr[i] & 1: odd = sub_parity[0] + 1 even = sub_parity[1] else: odd = sub_parity[1...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST VAR VAR VAR VAR RETURN VAR
Given an array Arr[] of size N. Find the number of subarrays whose sum is an even number. Example 1: Input: N = 6 Arr[] = {1, 2, 2, 3, 4, 1} Output: 9 Explanation: The array {1, 2, 2, 3, 4, 1} has 9 such possible subarrays. These are- {1, 2, 2, 3} Sum = 8 {1, 2, 2, 3, 4} Sum = 12 {2} ...
def countSpecial(n, arr): e, o = 0, 0 if arr[0] % 2 == 1: o += 1 else: e += 1 for i in range(1, n): arr[i] = arr[i - 1] + arr[i] if arr[i] % 2 == 1: o += 1 else: e += 1 result = e * (e + 1) // 2 result += o * (o + 1) // 2 - o re...
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR BIN...
Given an array Arr[] of size N. Find the number of subarrays whose sum is an even number. Example 1: Input: N = 6 Arr[] = {1, 2, 2, 3, 4, 1} Output: 9 Explanation: The array {1, 2, 2, 3, 4, 1} has 9 such possible subarrays. These are- {1, 2, 2, 3} Sum = 8 {1, 2, 2, 3, 4} Sum = 12 {2} ...
class Solution: def countEvenSum(self, arr, n): c = 0 f = [0, 0] s = 0 for i in range(n): s += arr[i] if s % 2 == 0: c += f[0] + 1 f[0] += 1 else: c += f[1] f[1] += 1 return c
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER NUMBER RETURN VAR
Given an array Arr[] of size N. Find the number of subarrays whose sum is an even number. Example 1: Input: N = 6 Arr[] = {1, 2, 2, 3, 4, 1} Output: 9 Explanation: The array {1, 2, 2, 3, 4, 1} has 9 such possible subarrays. These are- {1, 2, 2, 3} Sum = 8 {1, 2, 2, 3, 4} Sum = 12 {2} ...
class Solution: def countEvenSum(self, arr, n): currsum = 0 hm = {} count = 0 for i in range(n): currsum += arr[i] if currsum % 2 == 0: count += 1 if hm.get(2): count += hm[2] hm[2] += 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER IF FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER RETURN V...
Given an array Arr[] of size N. Find the number of subarrays whose sum is an even number. Example 1: Input: N = 6 Arr[] = {1, 2, 2, 3, 4, 1} Output: 9 Explanation: The array {1, 2, 2, 3, 4, 1} has 9 such possible subarrays. These are- {1, 2, 2, 3} Sum = 8 {1, 2, 2, 3, 4} Sum = 12 {2} ...
class Solution: def countEvenSum(self, arr, n): sm = 0 ev, od = 0, 0 for i in range(n): sm += arr[i] if sm % 2 == 0: ev += 1 else: od += 1 return ev * (ev + 1) // 2 + od * (od - 1) // 2
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER
Given an array Arr[] of size N. Find the number of subarrays whose sum is an even number. Example 1: Input: N = 6 Arr[] = {1, 2, 2, 3, 4, 1} Output: 9 Explanation: The array {1, 2, 2, 3, 4, 1} has 9 such possible subarrays. These are- {1, 2, 2, 3} Sum = 8 {1, 2, 2, 3, 4} Sum = 12 {2} ...
class Solution: def countEvenSum(self, arr, n): odd = 0 even = 0 cnt = 0 for i in range(len(arr)): if arr[i] % 2 == 0: even = even + 1 else: tmp = even even = odd odd = tmp + 1 cnt +=...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR
Given an array Arr[] of size N. Find the number of subarrays whose sum is an even number. Example 1: Input: N = 6 Arr[] = {1, 2, 2, 3, 4, 1} Output: 9 Explanation: The array {1, 2, 2, 3, 4, 1} has 9 such possible subarrays. These are- {1, 2, 2, 3} Sum = 8 {1, 2, 2, 3, 4} Sum = 12 {2} ...
class Solution: def countEvenSum(self, arr, n): even = 0 odd = 0 sume = 0 ans = 0 for a in arr: sume += a if sume % 2 == 0: ans += 1 + even even += 1 else: ans += odd odd += 1...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER RETURN VAR
Given an array arr[] of n integers, where each integer is greater than 1. The task is to find the number of Full binary tree from the given integers, such that each non-leaf node value is the product of its children value. Note: Each integer can be used multiple times in a full binary tree. The answer can be large, ret...
class Solution: def numoffbt(self, arr, n): mod = 1000000007 dicti = {x: (1) for x in arr} newarr = sorted(dicti.keys()) sol = 0 for i in newarr: for j in range(2 * i, min(i * i + 1, newarr[-1] + 1), i): if j in dicti and j // i in dicti: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR V...
Given an array arr[] of n integers, where each integer is greater than 1. The task is to find the number of Full binary tree from the given integers, such that each non-leaf node value is the product of its children value. Note: Each integer can be used multiple times in a full binary tree. The answer can be large, ret...
class Solution: def numoffbt(self, arr, n): ans = 0 min_a = min(arr) max_a = max(arr) dp = [0] * (max_a + 1) for i in arr: dp[i] = 1 for i in range(min_a, max_a + 1): if dp[i] != 0: j = i + i while j <= max_a an...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR IF VAR VAR NUMBER VAR ...
Given an array arr[] of n integers, where each integer is greater than 1. The task is to find the number of Full binary tree from the given integers, such that each non-leaf node value is the product of its children value. Note: Each integer can be used multiple times in a full binary tree. The answer can be large, ret...
class Solution: def numoffbt(self, arr, n): N = max(arr) + 2 mod = int(1000000000.0) + 7 chk = [0] * N ans = 0 for i in range(n): chk[arr[i]] = 1 for i in range(N): if chk[i]: for j in range(2 * i, N, i): if...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR IF VAR VAR NUMBER BIN_O...
Given an array arr[] of n integers, where each integer is greater than 1. The task is to find the number of Full binary tree from the given integers, such that each non-leaf node value is the product of its children value. Note: Each integer can be used multiple times in a full binary tree. The answer can be large, ret...
def binary_search(arr, low, high, x): if high >= low: mid = (high + low) // 2 if arr[mid] == x: return mid elif arr[mid] > x: return binary_search(arr, low, mid - 1, x) else: return binary_search(arr, mid + 1, high, x) else: return -1 ...
FUNC_DEF IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN V...
Given an array arr[] of n integers, where each integer is greater than 1. The task is to find the number of Full binary tree from the given integers, such that each non-leaf node value is the product of its children value. Note: Each integer can be used multiple times in a full binary tree. The answer can be large, ret...
class Solution: def numoffbt(self, arr, n): min1 = 9999999999 max1 = -999999999 for i in arr: min1 = min(min1, i) max1 = max(max1, i) dp = [0] * (max1 + 1) for i in range(n): dp[arr[i]] = 1 c = 0 for i in range(min1, max1 +...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN ...
Given an array arr[] of n integers, where each integer is greater than 1. The task is to find the number of Full binary tree from the given integers, such that each non-leaf node value is the product of its children value. Note: Each integer can be used multiple times in a full binary tree. The answer can be large, ret...
class Solution: def numoffbt(self, arr, n): mod = 10**9 + 7 maximum = max(arr) dp = [(0) for i in range(maximum + 1)] for i in arr: dp[i] = 1 ans = 0 for i in range(2, maximum + 1): if dp[i] == 0: continue ans += dp...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN...
Given an array arr[] of n integers, where each integer is greater than 1. The task is to find the number of Full binary tree from the given integers, such that each non-leaf node value is the product of its children value. Note: Each integer can be used multiple times in a full binary tree. The answer can be large, ret...
class Solution: def numoffbt(self, arr, n): maxvalue = -float("inf") minvalue = float("inf") for i in range(n): maxvalue = max(maxvalue, arr[i]) minvalue = min(minvalue, arr[i]) mark = [0] * (maxvalue + 2) value = [0] * (maxvalue + 2) for i in...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ...
Given an array arr[] of n integers, where each integer is greater than 1. The task is to find the number of Full binary tree from the given integers, such that each non-leaf node value is the product of its children value. Note: Each integer can be used multiple times in a full binary tree. The answer can be large, ret...
class Solution: def numoffbt(self, arr, n): mod = 10**9 + 7 maxrange = max(arr) minrange = min(arr) present = {arr[i]: (True) for i in range(0, n)} dp = [0] * (maxrange + 2) for i in range(0, n): present[arr[i]] = True dp[arr[i]] = 1 a...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VA...
Read problems statements in Mandarin Chinese and Russian. Chef likes trees a lot. Today he has an infinte full binary tree (each node has exactly two childs) with special properties. Chef's tree has the following special properties : Each node of the tree is either colored red or black. Root of the tree is black int...
root = 0 for _ in range(int(input())): q = list(map(str, input().split())) if q[0] == "Qi": root = (root + 1) % 2 else: x = int(q[1]) y = int(q[2]) xca = [] yca = [] lxca = 0 lyca = 0 while x > 0: lxca += 1 xca.append(x)...
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER...
Read problems statements in Mandarin Chinese and Russian. Chef likes trees a lot. Today he has an infinte full binary tree (each node has exactly two childs) with special properties. Chef's tree has the following special properties : Each node of the tree is either colored red or black. Root of the tree is black int...
ini = {"odd": "black", "even": "red"} for _ in range(int(input())): q = [i for i in input().split()] if q[0] == "Qi": temp = ini["odd"] ini["odd"] = ini["even"] ini["even"] = temp else: a, b = f"{int(q[1]):b}", f"{int(q[2]):b}" k = 0 count = {"black": 0, "red"...
ASSIGN VAR DICT STRING STRING STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR VAR STRING ASSIGN VAR STRING VAR STRING ASSIGN VAR STRING VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER STRING FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR...
Read problems statements in Mandarin Chinese and Russian. Chef likes trees a lot. Today he has an infinte full binary tree (each node has exactly two childs) with special properties. Chef's tree has the following special properties : Each node of the tree is either colored red or black. Root of the tree is black int...
def dec_to_bin(z): return int(bin(z)[2:]) testCases = int(input()) baseBlack = 1 for i in range(testCases): theStr = input() if theStr == "Qi": baseBlack = -baseBlack else: Color, Fir, Sec = theStr.split() if Color[1] == "b": theColor = 1 else: t...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VA...
Read problems statements in Mandarin Chinese and Russian. Chef likes trees a lot. Today he has an infinte full binary tree (each node has exactly two childs) with special properties. Chef's tree has the following special properties : Each node of the tree is either colored red or black. Root of the tree is black int...
t = int(input()) flag = False while t: t -= 1 inp = input() inp = inp.split() query = inp[0] if query == "Qi": if flag == True: flag = False else: flag = True else: x = int(inp[1]) y = int(inp[2]) c = 0 start = "Black" ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER IF VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRIN...
Read problems statements in Mandarin Chinese and Russian. Chef likes trees a lot. Today he has an infinte full binary tree (each node has exactly two childs) with special properties. Chef's tree has the following special properties : Each node of the tree is either colored red or black. Root of the tree is black int...
reverse = 0 for _ in range(int(input())): s = input().split() if s[0] == "Qb" or s[0] == "Qr": x = int(s[1]) y = int(s[2]) binx = bin(x)[2:] biny = bin(y)[2:] m = len(binx) n = len(biny) a = 0 if m < n: while a < m and binx[a] == biny[a...
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIG...
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, S, K): numStack = [] for num in S: while K > 0 and len(numStack) > 0 and num < numStack[-1]: numStack.pop() K -= 1 else: numStack.append(num) if K > 0: for _ in range(...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR WHILE VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN FUNC_CALL VAR FUNC_CALL STRING VAR
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, s, k): num = "" num = s st = list() for n in num: while st and k and st[-1] > n: st.pop() k -= 1 if st or n is not "0": st.append(n) if k: st = st[0:-k...
CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR WHILE VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR VAR NUMBER VAR RETURN FUNC_CALL STRING VAR STRING
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, S, K): res = [] counter = 0 n = len(S) if n == K: return "0" for i in range(n): while K and res and res[-1] > S[i]: res.pop() K -= 1 res.append(S[i]) while K: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN STRING FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR WHILE VAR EXPR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL FUNC_CALL STRING VAR STRING STRING
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, num, k): s = [] for i in num: while s and int(i) < s[-1] and k != 0: s.pop() k -= 1 s.append(int(i)) while k: s.pop() k -= 1 ans = "" for j in s: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR STRING STRING
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, s, k): if k >= len(s): return 0 if k == 0: return s st = [s[0]] for i in s[1:]: while k > 0 and st and i < st[-1]: st.pop() k -= 1 st.append(i) st = st[: l...
CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR NUMBER RETURN VAR ASSIGN VAR LIST VAR NUMBER FOR VAR VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL STRING VAR
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, S, K): stack = ["0"] for item in S: while K and stack[-1] > item: stack.pop() K -= 1 stack.append(item) return int("".join(stack[:-K])) if K else int("".join(stack))
CLASS_DEF FUNC_DEF ASSIGN VAR LIST STRING FOR VAR VAR WHILE VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR FUNC_CALL STRING VAR
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, S, K): stack = [] ans = "" for i in range(len(S)): while len(stack) != 0 and K != 0 and stack[-1] > int(S[i]): stack.pop() K -= 1 if len(stack) == 0 and int(S[i]) == 0: continue ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR ...
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, s, k): st = [] for i in s: while st and k > 0 and st[-1] > i: st.pop() k -= 1 st.append(i) if k: st = st[0:-k] res = "".join(st) return str(int(res)) if res else "0"
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR WHILE VAR VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL STRING VAR RETURN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, arr, k): n = len(arr) stk = [] for i in arr: while stk and k > 0 and int(stk[-1]) > int(i): stk.pop() k -= 1 if stk or int(i) > 0: stk.append(i) while stk and k > 0: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR WHILE VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER AS...
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, s, k): stack = [] for i in s: while stack and stack[-1] > i and k > 0: stack.pop() k -= 1 stack.append(i) stack = stack[: len(stack) - k] r = "".join(stack) return str(int(r))
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR WHILE VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, S, k): l = len(S) ans = "" st = [] for i in range(l): while st and k > 0 and st[-1] > S[i]: st.pop() k -= 1 st.append(S[i]) if k > 0: while k > 0: st.p...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_C...
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, S, K): stack = "0" while K: if not S: return int(stack[:-K]) elif stack[-1] > S[0]: stack = stack[:-1] K -= 1 else: stack += S[0] S = S[1:] ...
CLASS_DEF FUNC_DEF ASSIGN VAR STRING WHILE VAR IF VAR RETURN FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, S, K): ans = [] for c in S: while len(ans) and ans[-1] > c and K > 0: ans.pop() K -= 1 if len(ans) > 0 or c != "0": ans.append(c) while len(ans) and K > 0: K -= 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR WHILE FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR STRING EXPR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER RETURN STRING ASSIGN VAR STRING FOR VA...
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, S, K): stack = [] S = int(S) S = str(S) for i in S: if len(stack) == 0: stack.append(i) else: num = stack[-1] while num > i and K > 0: x = stack.pop() ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VA...
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, s, k): n = len(s) if n == k: return 0 stack = [] stack.append(s[0]) for i in range(1, n): while stack and s[i] < stack[-1] and k > 0: stack.pop() k -= 1 stack.append(s...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR WHILE VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL...
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, s, k): stk = [] res = [] ans = "" n = len(s) for i in range(n - 1, -1, -1): while len(stk) > 0 and s[i] <= s[stk[-1]]: stk.pop() if len(stk) == 0: res.append(n) else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL...
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, S, k): arr = [] for r in S: arr.append(r) ans = "" stck = [] lis = [] i = 0 while i < len(arr): if k > 0: if arr[i] == 0: i += 1 pass ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC...
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, S, K): st = [] for i in S: ele = int(i) while len(st) and K > 0 and ele < st[-1]: st.pop() K = K - 1 if ele != 0 or len(st) != 0: st.append(ele) while len(st) and K > ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER I...
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, S, K): st = [] for i in S: while st and K and st[-1] > i: st.pop() K -= 1 if st or i is not "0": st.append(i) if K: st = st[:-K] res = "" for ele in st...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR WHILE VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING FOR VAR VAR VAR VAR IF VAR STRING RETURN NUMBER RETURN VAR
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, num, k): stack = [] l = list(num) if k == len(l): return "0" for i in l: if k == 0: stack.append(i) elif stack == []: stack.append(i) elif stack[-1] <= i: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR RETURN STRING FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR LIST EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR WHILE VAR LIST VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXP...
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, S, K): st = [] for n in S: while K > 0 and len(st) > 0 and st[-1] > n: K -= 1 st.pop() st.append(n) st = st[: len(st) - K] ans = "".join(st) return str(int(ans)) if ans else "0"
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR WHILE VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR RETURN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, S, K): stack = [] i = 0 while K > 0 and i < len(S): if stack == []: stack.append(S[i]) i += 1 elif stack[-1] > S[i]: stack.pop() K -= 1 elif stack[-1] ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ...
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, S, K): s = [] for c in S: while len(s) > 0 and s[-1] > c and K > 0: s.pop() K -= 1 s.append(c) while K > 0: s.pop() K -= 1 start = len(s) for i in range(le...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR IF VAR FUNC_CA...
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, S, K): s = [] n = len(S) for i in S: while s and K > 0 and s[-1] > i: s.pop() K -= 1 if s or i != "0": s.append(i) while s and K: s.pop() K -= 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR WHILE VAR VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR WHILE VAR VAR EXPR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN STRING ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR B...
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, S, K): stack = [] if K > len(S): return "0" n = len(S) for i in range(n): while stack and int(stack[-1]) > int(S[i]) and K > 0: stack.pop() K -= 1 stack.append(S[i]) w...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST IF VAR FUNC_CALL VAR VAR RETURN STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC...
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, S, K): stack = [] for x in S: while stack and int(stack[-1]) > int(x) and K != 0: stack.pop() K -= 1 stack.append(x) while K != 0: stack.pop() K -= 1 return "".joi...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR WHILE VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL FUNC_CALL STRING VAR STRING NUMBER
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, S, k): stack = [] for i in S: while stack and stack[-1] > i and k > 0: stack.pop() k = k - 1 if len(stack) != 0 or i != "0": stack.append(i) while len(stack) != 0 and k > 0: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR WHILE VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR STRING EXPR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN ST...
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, S, K): stack = [S[0]] for i in S[1:]: while stack and K and i < stack[-1]: K -= 1 stack.pop() stack.append(i) if K: for i in range(K): stack.pop() return int("...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST VAR NUMBER FOR VAR VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN FUNC_CALL VAR FUNC_CALL STRING VAR
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, a, k): st = [] ans = "" n = len(a) for c in a: while st and k > 0 and int(c) < int(st[-1]): st.pop() k -= 1 if st or c != "0": st.append(c) while st and k: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR WHILE VAR VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR WHILE VAR VAR EXPR FUNC_CALL VAR VAR NUMBER IF VAR RETURN STRING FOR VAR FUNC_CALL VAR FUNC...
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, s, k): st = [] for el in s: if not st and el == "0": continue elif not st: st.append(el) elif st[-1] <= el: st.append(el) else: while st and st[-1]...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR VAR STRING IF VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR BIN_O...
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, S, K): s = [] ans = "" n = len(S) for i in range(n): while s and s[-1] > S[i] and K > 0: s.pop() K = K - 1 s.append(S[i]) while K > 0 and s: s.pop() K = K ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR WHILE VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP ...
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, num, k): st = [] if len(num) <= k: return "0" for i in range(len(num)): if len(st) == 0: st.append(num[i]) else: while len(st) and st[-1] > num[i] and k > 0: st.po...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST IF FUNC_CALL VAR VAR VAR RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR ...
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, S, K): stack = list() for i in range(len(S)): if K == 0: stack.append(S[i]) continue if i == 0: if S[i] == 0: continue else: stack....
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR NUMB...
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, S, K): if len(S) == K: return "0" stack = [] for n in S: while stack and K and int(stack[-1]) > int(n): stack.pop() K -= 1 stack.append(n) while K: stack.pop() ...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN STRING ASSIGN VAR LIST FOR VAR VAR WHILE VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR EXPR FUNC_CALL VAR VAR NUMBER IF VAR RETURN STRING RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, S, K): stack = [] stack.append(S[0]) for i in range(1, len(S)): while (K > 0 and len(stack) > 0) and S[i] < stack[-1]: stack.pop() K -= 1 stack.append(S[i]) while K != 0: stac...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR WHILE VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE V...
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, s, k): s = list(s) stack = [s[0]] n = len(s) index = n for i in range(1, n): if k == 0: index = i break if len(stack) == 0 or stack[-1] < s[i]: stack.append(s[i]) ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR WHILE VAR NUMBER VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NU...
Given a non-negative integer S represented as a string, remove K digits from the number so that the new number is the smallest possible. Note : The given num does not contain any leading zero. Example 1: Input: S = "149811", K = 3 Output: 111 Explanation: Remove the three digits 4, 9, and 8 to form the new number 111 ...
class Solution: def removeKdigits(self, S, K): stack = [] for i in S: while K > 0 and len(stack) > 0 and stack[-1] > i: stack.pop() K -= 1 if len(stack) > 0 or i != "0": stack.append(i) while len(stack) > 0 and K > 0: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR WHILE VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR STRING EXPR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN STRING RETURN FUN...