description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
n, m = list(map(int, input().split())) a = [] for i in range(n): a.append(input()) d = 0 for b in range(n, 0, -1): for c in range(m, 0, -1): for i in range(n - b + 1): for j in range(m - c + 1): z = 0 for k in range(b): if a[i + k][j : j + ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
from sys import stdin n, m = [int(i) for i in stdin.readline().split(" ")] space = [] for i in range(0, n): space.append(stdin.readline() + "") rightOnes = [] for i in range(0, n): curR = [] for j in range(0, m): for k in range(j, m): if space[i][k] == "1": curR.append(k...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR STRING EXPR F...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
n, m = map(int, input().split()) input = [input() for _ in range(n)] d = [] for _ in range(n): d.append([(0) for _ in range(m)]) def a(i, j): return 0 if i < 0 or j < 0 else d[i][j] for i in range(n): for j in range(m): d[i][j] = int(input[i][j]) - a(i - 1, j - 1) + a(i, j - 1) + a(i - 1, j) p =...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF RETURN VAR NUMBER VAR NUMBER NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VA...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
n, m = [int(x) for x in input().split()] lines = [] for y in range(n): s = input() lines.append(s) rightest = {} lowest = {} for start_y in range(n): for start_x in range(m): p = start_x, start_y if lines[start_y][start_x] == "1": rightest[p] = -1 lowest[p] = -1 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
import sys def input(): return sys.stdin.readline().strip() def iinput(): return int(input()) def rinput(): return map(int, sys.stdin.readline().strip().split()) def get_list(): return list(map(int, sys.stdin.readline().strip().split())) mod = int(1000000000.0) + 7 n, m = rinput() room = [] fo...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSI...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
n, m = map(int, input().split()) y = [input() for i in range(n)] v = 0 for i in range(n): for j in range(m): for k in range(i, n): for s in range(j, m): if all(y[x][j : s + 1] == "0" * (s - j + 1) for x in range(i, k + 1)): v = max(v, 2 * (k - i + s - j + 2)) ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP STRING BIN_OP BIN_OP VAR VAR NUM...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
line = input().split(" ") rows = int(line[0]) cols = int(line[1]) table = [0] * rows table = [input() for i in range(rows)] D = [ [[[None for i in range(cols)] for i in range(rows)] for i in range(cols)] for i in range(rows) ] maxper = 0 def biggestPerimeter(table): global maxper for x1 in range(0, ro...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NONE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUN...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
n, m = map(int, input().split()) a = [list(map(int, input())) for _ in range(n)] hlf = 2 for ra in range(n): for rb in range(ra, n): cols = [] for cc in range(m): ok = 1 for rr in range(ra, rb + 1): if a[rr][cc]: ok = 0 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
n, m = map(int, input().split()) room = [input() for _ in range(n)] dp = [[[[(0) for _ in range(m)] for _ in range(n)] for _ in range(m)] for _ in range(n)] def check(a, b, c, d): if ( c == a and b == d or (dp[a][b][c - 1][d] or c - a == 0) and (dp[a][b][c][d - 1] or d - b == 0) ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR BIN_OP VAR...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
graph = [] def perimeter(x0, y0, x1, y1): return (x1 - x0 + 1) * 2 + (y1 - y0 + 1) * 2 def is_valid(g, k, x0, y0, x1, y1): ok = k.get((x0, y0, x1, y1)) if ok is None: ok = g[x1][y1] == "0" if x1 > x0: ok = ok and is_valid(g, k, x0, y0, x1 - 1, y1) if y1 > y0: ...
ASSIGN VAR LIST FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NONE ASSIGN VAR VAR VAR VAR STRING IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
n, m = [int(i) for i in input().split(" ")] matrix = [] for i in range(n): matrix.append([j for j in input()]) dp = [] for i in range(n): dp.append([]) for j in range(m): dp[i].append([]) for k in range(n): dp[i][j].append([]) for _ in range(m): dp[i][...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
n, m = [int(i) for i in input().split(" ")] matrix = [] far = [] t = 0 for i in range(n): matrix.append([j for j in input()]) far.append([None for _ in range(m)]) for i in range(n): for j in reversed(range(m)): if matrix[i][j] == "1": far[i][j] = j - 1 elif j == m - 1: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NONE VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING A...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
def isBet(one, two, thr): (a, b), (c, d), (e, f) = one, two, thr x = False y = False if a == c: x = e == a elif a > c: if e >= c and e <= a: x = True elif e <= c and e >= a: x = True if b == d: y = f == b elif b > d: if f >= d and f <= ...
FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR IF VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR IF VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER RE...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
n, m = map(int, input().split()) L = [list(map(int, input())) for i in range(n)] A = [([0] * (m + 1)) for i in range(n)] for i in range(n): for j in range(m): A[i][j + 1] = A[i][j] + L[i][j] out = 0 for x1 in range(m): for x2 in range(x1, m): s = 0 for y in range(n): if A[y][...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VA...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
n, m = map(int, input().split()) s = [([0] + list(map(int, input()))) for i in range(n)] for i in range(n): for j in range(m): s[i][j + 1] += s[i][j] d = 1 for i in range(0, m): for j in range(i + 1, m + 1): t = [-1] + [k for k in range(n) if s[k][j] - s[k][i]] + [n] p = max(t[i + 1] - t...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BI...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
n, m = map(int, input().split()) s = [list(input()) for i in range(n)] cnt = [([0] * (m + 1)) for i in range(n + 1)] for i in range(n): for j in range(m): if s[i][j] == "1": cnt[i + 1][j + 1] += 1 for i in range(n): for j in range(m + 1): cnt[i + 1][j] += cnt[i][j] for i in range(n +...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMB...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
R = lambda: map(int, input().split()) n, m = R() rm = [list(map(int, input())) for i in range(n)] dp = [([0] * (m + 1)) for _ in range(n + 1)] for i in range(n): for j in range(m): dp[i][j] = rm[i][j] + dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] res = 0 for r1 in range(n): for c1 in range(m): ...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
def no(a, b): a, b = str(min(a, b)), str(max(a, b)) a = "0" * (len(b) - len(a)) + a s = "" for i in range(len(a)): if a[i] == "0" and b[i] == "0": s += "0" else: s += "1" return int(s) n, m = map(int, input().split()) a = [-1] * n mp = 0 for i in range(n): ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR STRING VAR STRING RETURN FUNC_CALL VAR VAR ASSIGN ...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
n, m = map(int, input().split()) ar = [([0] * (m + 1)) for i in range(n + 1)] def sm(x1, y1, x2, y2): return ar[x1 - 1][y1 - 1] + ar[x2][y2] - ar[x1 - 1][y2] - ar[x2][y1 - 1] for i in range(1, n + 1): s = input() for j in range(1, m + 1): ar[i][j] = ( ar[i - 1][j] + ar[i]...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VA...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
m, n = input().split() m = int(m) n = int(n) lis = [] maxx = 0 sat = 0 sot = 0 for i in range(m): lis.append(input()) for i in range(m): for j in range(n): sat = sot = 0 if lis[i][j] == "0": sat = 1 sot = 1 ma = 0 q = 0 for k in range(i...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR VAR STRIN...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
n, m = map(int, input().split()) X = [] for i in range(n): temp = list(str(input())) temp = [int(c) for c in temp] X.append(temp) s = [([0] * (m + 1)) for _ in range(n + 1)] for i in range(n): for j in range(m): s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + X[i][j] ans = 0 for y1 in ra...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VA...
Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that it...
import sys input = lambda: sys.stdin.readline().strip() n, m = [int(x) for x in input().split()] g = [input() for i in range(n)] print( max( 2 * (ii - i) + 2 * (jj - j) for i in range(n) for j in range(m) for ii in range(i + 1, n + 1) for jj in range(j + 1, m + 1) if...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR...
Given an infinite number line. You start at 0 and can go either to the left or to the right. The condition is that in the i^{th} move, youmust take i steps. Given a destination D , find the minimum number of steps required to reach that destination. Example 1: Input: D = 2 Output: 3 Explaination: The steps takn are +1,...
class Solution: def minSteps(self, target): s = 0 i = 0 while s < target: s += i i += 1 while (s - target) % 2 == 1: s += i i += 1 return i - 1
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER RETURN BIN_OP VAR NUMBER
Given an infinite number line. You start at 0 and can go either to the left or to the right. The condition is that in the i^{th} move, youmust take i steps. Given a destination D , find the minimum number of steps required to reach that destination. Example 1: Input: D = 2 Output: 3 Explaination: The steps takn are +1,...
import sys def steps(source, step, dest): if abs(source) > dest: return sys.maxsize if source == dest: return step pos = steps(source + step + 1, step + 1, dest) neg = steps(source - step - 1, step + 1, dest) return min(pos, neg) class Solution: def minSteps(self, D): ...
IMPORT FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN VAR IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR RETU...
Given an infinite number line. You start at 0 and can go either to the left or to the right. The condition is that in the i^{th} move, youmust take i steps. Given a destination D , find the minimum number of steps required to reach that destination. Example 1: Input: D = 2 Output: 3 Explaination: The steps takn are +1,...
class Solution: def minSteps(self, D): sm = 0 st = 1 while True: sm += st if sm == D: return st if sm > D and (sm - D) % 2 == 0: return st st += 1
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER VAR VAR IF VAR VAR RETURN VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN VAR VAR NUMBER
Given an infinite number line. You start at 0 and can go either to the left or to the right. The condition is that in the i^{th} move, youmust take i steps. Given a destination D , find the minimum number of steps required to reach that destination. Example 1: Input: D = 2 Output: 3 Explaination: The steps takn are +1,...
import sys class Solution: def minSteps(self, D): i = 1 while True: if i == D: return i if i > D: if (i - D) % 2 == 0: return i elif i % 2 == 0: return i + 1 else: ...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR RETURN VAR IF VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN VAR IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER VAR VAR VAR NUMBER
Given an infinite number line. You start at 0 and can go either to the left or to the right. The condition is that in the i^{th} move, youmust take i steps. Given a destination D , find the minimum number of steps required to reach that destination. Example 1: Input: D = 2 Output: 3 Explaination: The steps takn are +1,...
class Solution: def minSteps(self, D): def rec(D, curr=0, i=1): if curr < D: return rec(D, curr + i, i + 1) if (curr - D) % 2: return rec(D, curr + i, i + 1) return i - 1 return rec(D) if __name__ == "__main__": t = int(inp...
CLASS_DEF FUNC_DEF FUNC_DEF NUMBER NUMBER IF VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CAL...
Given an infinite number line. You start at 0 and can go either to the left or to the right. The condition is that in the i^{th} move, youmust take i steps. Given a destination D , find the minimum number of steps required to reach that destination. Example 1: Input: D = 2 Output: 3 Explaination: The steps takn are +1,...
class Solution: def minSteps(self, D): t = 0 if D == 1: return 1 for i in range(1, D * D): t += i if t == D: return i if t > D: if (t - D) % 2 == 0: return i
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR IF VAR VAR RETURN VAR IF VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN VAR
Given an infinite number line. You start at 0 and can go either to the left or to the right. The condition is that in the i^{th} move, youmust take i steps. Given a destination D , find the minimum number of steps required to reach that destination. Example 1: Input: D = 2 Output: 3 Explaination: The steps takn are +1,...
class Solution: def minSteps(self, D): n = 0 s = 0 while s < D: s += n n += 1 n -= 1 d = s - D if d % 2 == 0: return n elif n % 2 == 0: return n + 1 else: return n + 2
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN VAR IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER
Given an infinite number line. You start at 0 and can go either to the left or to the right. The condition is that in the i^{th} move, youmust take i steps. Given a destination D , find the minimum number of steps required to reach that destination. Example 1: Input: D = 2 Output: 3 Explaination: The steps takn are +1,...
class Solution: def minSteps(self, D): D = abs(D) if D == 0: return 0 currsum = 0 steps = 0 i = 1 while currsum < D: currsum += i i += 1 steps += 1 if currsum == D: return steps while (currsu...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN VAR WHILE BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR NUMBER RETURN VAR
Given an infinite number line. You start at 0 and can go either to the left or to the right. The condition is that in the i^{th} move, youmust take i steps. Given a destination D , find the minimum number of steps required to reach that destination. Example 1: Input: D = 2 Output: 3 Explaination: The steps takn are +1,...
class Solution: def minSteps(self, n): i = 1 sm = 0 while sm != n: sm += i if sm == n: return i if sm > n: if (sm - n) % 2 == 0: return i i += 1 if sm == n: return i
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR RETURN VAR IF VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN VAR VAR NUMBER IF VAR VAR RETURN VAR
Given an infinite number line. You start at 0 and can go either to the left or to the right. The condition is that in the i^{th} move, youmust take i steps. Given a destination D , find the minimum number of steps required to reach that destination. Example 1: Input: D = 2 Output: 3 Explaination: The steps takn are +1,...
class Solution: def minSteps(self, D): ans, sum = 0, 0 while 1: sum += ans ans += 1 if sum == D: return ans - 1 if sum > D and (sum - D) % 2 == 0: return ans - 1 return 0
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER WHILE NUMBER VAR VAR VAR NUMBER IF VAR VAR RETURN BIN_OP VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER RETURN NUMBER
Given an infinite number line. You start at 0 and can go either to the left or to the right. The condition is that in the i^{th} move, youmust take i steps. Given a destination D , find the minimum number of steps required to reach that destination. Example 1: Input: D = 2 Output: 3 Explaination: The steps takn are +1,...
class Solution: def minSteps(self, D): N = int(((1 + 8 * D) ** 0.5 - 1) / 2) L = N * (N + 1) // 2 if L == D: return N if (L + N + 1 - D) % 2 == 0: return N + 1 return N + 3 - N % 2
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR RETURN VAR IF BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER BIN_O...
Given an infinite number line. You start at 0 and can go either to the left or to the right. The condition is that in the i^{th} move, youmust take i steps. Given a destination D , find the minimum number of steps required to reach that destination. Example 1: Input: D = 2 Output: 3 Explaination: The steps takn are +1,...
class Solution: def minSteps(self, D): if D == 1: return 1 n = 1 while n: z = n * (n - 1) // 2 if z - D >= 0 and (z - D) % 2 == 0: return n - 1 n += 1 return 0
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER VAR NUMBER RETURN NUMBER
Given an infinite number line. You start at 0 and can go either to the left or to the right. The condition is that in the i^{th} move, youmust take i steps. Given a destination D , find the minimum number of steps required to reach that destination. Example 1: Input: D = 2 Output: 3 Explaination: The steps takn are +1,...
class Solution: def minSteps(self, D): def rec(sum, step, D): if sum >= D and (sum - D) % 2 == 0: return step step = step + 1 sum = sum + step return rec(sum, step, D) return rec(0, 0, D)
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR RETURN FUNC_CALL VAR NUMBER NUMBER VAR
Given an infinite number line. You start at 0 and can go either to the left or to the right. The condition is that in the i^{th} move, youmust take i steps. Given a destination D , find the minimum number of steps required to reach that destination. Example 1: Input: D = 2 Output: 3 Explaination: The steps takn are +1,...
import sys sys.setrecursionlimit(10**9) class Solution: def recur(self, s, d, i): global dp import sys key = str(s) + "-" + str(i) if abs(s) > d: return sys.maxsize if s == d: return 0 if key in dp: return dp[key] l = 1...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF IMPORT ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN VAR IF VAR VAR RETURN NUMBER IF VAR VAR RETURN VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_O...
Given an infinite number line. You start at 0 and can go either to the left or to the right. The condition is that in the i^{th} move, youmust take i steps. Given a destination D , find the minimum number of steps required to reach that destination. Example 1: Input: D = 2 Output: 3 Explaination: The steps takn are +1,...
class Solution: def minSteps(self, D): setti = set([0]) i = 0 while D not in setti: temp = set() i += 1 for item in setti: temp.add(item - i) temp.add(item + i) setti = temp return i
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR RETURN VAR
Given an infinite number line. You start at 0 and can go either to the left or to the right. The condition is that in the i^{th} move, youmust take i steps. Given a destination D , find the minimum number of steps required to reach that destination. Example 1: Input: D = 2 Output: 3 Explaination: The steps takn are +1,...
class Solution: def minSteps(self, target): steps = 0 source = 0 target = abs(target) while source < target: steps += 1 source += steps while (source - target) % 2 != 0: steps += 1 source += steps return steps
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR WHILE BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR RETURN VAR
Given an infinite number line. You start at 0 and can go either to the left or to the right. The condition is that in the i^{th} move, youmust take i steps. Given a destination D , find the minimum number of steps required to reach that destination. Example 1: Input: D = 2 Output: 3 Explaination: The steps takn are +1,...
class Solution: def solve(self, i, D, st, dp): if abs(i) > D: return 100000000 if i == D: return 0 if (i, st) in dp: return dp[i, st] left = self.solve(i - st, D, st + 1, dp) right = self.solve(i + st, D, st + 1, dp) dp[i, st] = 1 ...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN NUMBER IF VAR VAR RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR RETURN VAR VAR V...
Given an infinite number line. You start at 0 and can go either to the left or to the right. The condition is that in the i^{th} move, youmust take i steps. Given a destination D , find the minimum number of steps required to reach that destination. Example 1: Input: D = 2 Output: 3 Explaination: The steps takn are +1,...
class Solution: def minSteps(self, D): d = abs(D) cpos = 0 move_no = 1 steps = 0 while cpos < d: cpos += move_no move_no += 1 steps += 1 if cpos == d: return steps else: diff = cpos - d i...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN VAR IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER
Given an infinite number line. You start at 0 and can go either to the left or to the right. The condition is that in the i^{th} move, youmust take i steps. Given a destination D , find the minimum number of steps required to reach that destination. Example 1: Input: D = 2 Output: 3 Explaination: The steps takn are +1,...
class Solution: def minSteps(self, D): steps, curr = 0, 0 while curr < D: steps += 1 curr += steps while curr - D & 1: steps += 1 curr += steps return steps
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR NUMBER VAR VAR WHILE BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR RETURN VAR
Given an infinite number line. You start at 0 and can go either to the left or to the right. The condition is that in the i^{th} move, youmust take i steps. Given a destination D , find the minimum number of steps required to reach that destination. Example 1: Input: D = 2 Output: 3 Explaination: The steps takn are +1,...
class Solution: def minSteps(self, n): steps = 0 source = 0 while source < n: steps += 1 source += steps if source == n or (source - n) % 2 == 0: return steps while (n - source) % 2 != 0: steps += 1 source += steps ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN VAR WHILE BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR RETURN VAR
Given an infinite number line. You start at 0 and can go either to the left or to the right. The condition is that in the i^{th} move, youmust take i steps. Given a destination D , find the minimum number of steps required to reach that destination. Example 1: Input: D = 2 Output: 3 Explaination: The steps takn are +1,...
class Solution: def minSteps(self, D): D = abs(D) s = 0 i = 1 while s < D: s += i i += 1 i -= 1 if s == D: return i while 1: if (s + D) % 2 == 0: return i i += 1 s += i
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN VAR WHILE NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN VAR VAR NUMBER VAR VAR
Given an infinite number line. You start at 0 and can go either to the left or to the right. The condition is that in the i^{th} move, youmust take i steps. Given a destination D , find the minimum number of steps required to reach that destination. Example 1: Input: D = 2 Output: 3 Explaination: The steps takn are +1,...
class Solution: def minSteps(self, target): if target == 0: return 0 ans = 0 steps = 0 target = abs(target) while ans < target: ans += steps steps += 1 while (ans - target) % 2 == 1: ans += steps steps += 1 ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER RETURN BIN_OP VAR NUMBER
Given an infinite number line. You start at 0 and can go either to the left or to the right. The condition is that in the i^{th} move, youmust take i steps. Given a destination D , find the minimum number of steps required to reach that destination. Example 1: Input: D = 2 Output: 3 Explaination: The steps takn are +1,...
class Solution: def minSteps(self, D): positions = set([0]) mv = 0 while D not in positions: mv += 1 nxt = [] for i in positions: nxt.append(i + mv) nxt.append(i - mv) positions = set(nxt) return mv
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: if n > m: n, m = m, n res = n * m def dfs(heights, count, rem_area): nonlocal res if count >= res: return lowest_idx, lowest_height, width, prev = -1, math.inf,...
CLASS_DEF FUNC_DEF VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_DEF IF VAR VAR RETURN ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER V...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: ans = math.inf matrix = [([0] * m) for _ in range(n)] def dfs(r, c, count): nonlocal ans if count >= ans: return if r >= n: ans = count retu...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN IF VAR VAR ASSIGN VAR VAR RETURN IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR RETURN IF VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CA...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, m: int, n: int) -> int: cur = [0] * (n * m) q = [cur] step = 0 seen = {tuple(cur)} while q and step < n * m + 1: step += 1 nex = [] for cur in q: found = True for i ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR VAR ...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: self.best = m * n def dfs(heights, count): if min(heights) == n: self.best = min(self.best, count) return if count >= self.best: return min_height =...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN IF VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR ...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, m, n): self.best = n * m def dfs(heights, mvs): if mvs >= self.best: return if all(h == n for h in heights): self.best = min(self.best, mvs) return i = j = min(list(range(m...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR VAR FUNC_DEF IF VAR VAR RETURN IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: def dp(state): if state in cache: return cache[state] if state[::-1] in cache: return cache[state[::-1]] tmp = state if min(state) == n: return ...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF VAR VAR RETURN VAR VAR IF VAR NUMBER VAR RETURN VAR VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: memo = {} return self.dfs(n, m, memo) def dfs(self, x, y, memo): if x == 0 or y == 0: return 0 if x == y: return 1 if x == 1: return y if y == 1: re...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT RETURN FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN VAR IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CA...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: if m > n: n, m = m, n res, state = m * n, [0] * n def dfs(count): nonlocal res if count > res: return min_h = min(state) if min_h == m: ...
CLASS_DEF FUNC_DEF VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP LIST NUMBER VAR FUNC_DEF IF VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN ASSIGN VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: res = 0 dq = deque([[0] * m]) seen = {tuple([0] * m)} while dq: length = len(dq) for _ in range(length): curr = dq.popleft() minh = min(curr) s =...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP LIST NUMBER VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE BIN_O...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: dp = [([sys.maxsize] * (m + 1)) for _ in range(n + 1)] def getdp(n, m): if dp[n][m] != sys.maxsize: return dp[n][m] if n == 0 or m == 0: return 0 if m == n: ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR VAR VAR RETURN VAR VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUM...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: @lru_cache(None) def helper(heights): mh = min(heights) if mh == n: return 0 ret = float("inf") j = heights.index(mh) w = 1 while mh + w <= n an...
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def findSum(self, n, m, k): res = [] s = m * n hi = min(n, m) border = max(n, m) path = [1] * k while path[0] <= hi: i = k - 1 while i >= 0 and path[i] >= hi: i -= 1 if i == -1 or path[i] >= hi: ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR RETURN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: self.result = n * m heights = [0] * n def dfs(cur): if cur >= self.result: return curMinHeight = min(heights) if curMinHeight == m: self.result = cur ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF IF VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN ASSIGN VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: if n > m: n, m = m, n if m == n: return 1 res = [m * n] dp = {} def dfs(cnt, hs): if cnt > res[0]: return key = tuple(hs) if key in ...
CLASS_DEF FUNC_DEF VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR LIST BIN_OP VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR RETURN ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: if n > m: return self.tilingRectangle(m, n) ans = n * m h = [0] * n def getmin(l): minv = 100000 mini = -1 for i in range(len(l)): if l[i] < minv: ...
CLASS_DEF FUNC_DEF VAR VAR IF VAR VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR RETURN VAR VAR FUNC_DEF IF VAR VAR RETURN ASSIGN VAR VAR FU...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: self.result = n * m def dfs(heights, moves): if moves > self.result: return if all(h == n for h in heights): self.result = min(self.result, moves) return ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_DEF IF VAR VAR RETURN IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP ...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: res = float("inf") def tilingRectangle(self, n: int, m: int) -> int: s = {} def dfs(n, m, h, cnt): if cnt > self.res: return is_full = True pos = -1 minh = float("inf") for i in range(1, n + 1): ...
CLASS_DEF ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR RETURN ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR IF VAR ASSIGN VAR FUN...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int): cache = [[(-1) for i in range(m + 1)] for j in range(n + 1)] return self.helper(n, m, cache) def helper(self, n: int, m: int, cache) -> int: if n <= 0 or m <= 0: return 0 if n == 11 and m == 13 or n == 13 an...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR FUNC_DEF VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: if n == m: return 1 if n > m: n, m = m, n layers0 = [(0) for _ in range(n)] visited = {} ans = [n * m] def dfs(layers, stepsNow): if stepsNow > ans[0]: ...
CLASS_DEF FUNC_DEF VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR LIST BIN_OP VAR VAR FUNC_DEF IF VAR VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR RETURN ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: if n < m: n, m = m, n if m == n: return 1 heights = [0] * n dp = {} final = [m * n] def helper(heights, counts): key = tuple(heights) if counts >= final...
CLASS_DEF FUNC_DEF VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR DICT ASSIGN VAR LIST BIN_OP VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER RETURN IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR RETURN IF ...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: memo = {} def helper(w, h): if w > h: w, h = h, w if (w, h) not in memo: if w == h: ans = 1 elif w == 1: ans = h ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_C...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: h = [0] * m self.ans = m * n def dfs(h: List[int], cur: int) -> None: min_h = min(h) if min_h == n: self.ans = min(self.ans, cur) return if cur > self.ans: ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR VAR FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN IF VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP V...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: m, n = min(m, n), max(m, n) self.res = n * m self.H = n self.search(0, [0] * m) return self.res def search(self, count, heights): if count >= self.res: return min_h = min(heigh...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP LIST NUMBER VAR RETURN VAR VAR FUNC_DEF IF VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR ...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: if n < m: return self.tilingRectangle(m, n) h = [0] * m self.ans = 100000 self.dfs(n, m, h, 0) return self.ans def dfs(self, m, n, h, cur): if cur >= self.ans: return ...
CLASS_DEF FUNC_DEF VAR VAR IF VAR VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR VAR FUNC_DEF IF VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: if m == n: return 1 if n > m: m, n = n, m h_i = [0] * n visited = {} res = [m * n] def dfs(height, cnt): if cnt > res[0]: return status ...
CLASS_DEF FUNC_DEF VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR DICT ASSIGN VAR LIST BIN_OP VAR VAR FUNC_DEF IF VAR VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR RETURN ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIG...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, R, C): A = [([0] * C) for _ in range(R)] self.ans = R * C def search(r, c, steps): if steps >= self.ans: return if r == R: self.ans = steps return if c == C: ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_DEF IF VAR VAR RETURN IF VAR VAR ASSIGN VAR VAR RETURN IF VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: self.res = math.inf grid = [([False] * n) for _ in range(m)] def dfs(i, j, s): if s >= self.res: return elif i == m: self.res = s elif j == n: ...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN IF VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: self.best = m * n height = [0] * m def dfs(moves): if all(h == n for h in height): self.best = min(self.best, moves) return if moves >= self.best: retur...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN IF VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER NUMBER FOR VA...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: self.best = n * m def dfs(hts, mvs): if mvs >= self.best: return if all(h == n for h in hts): self.best = min(self.best, mvs) return i = min(list(ra...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_DEF IF VAR VAR RETURN IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR LIST NUMBER NUMBER FO...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: if n == m: return 1 if m > n: m, n = n, m @lru_cache(None) def helper(skyline): if all(h == n for h in skyline): return 0 ans = float("inf") ...
CLASS_DEF FUNC_DEF VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR ...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: d = gcd(n, m) if d != 1: return self.tilingRectangle(n // d, m // d) if n > m: n, m = m, n if m % n == 0: return m // n heights = [0] * n recs = [[0, 1]] CAP...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER RETURN BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR V...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: self.n = n self.m = m board = [([0] * n) for _ in range(m)] self.res = float("inf") self.dfs(board, 0) return self.res def dfs(self, board, count): if count >= self.res: return...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER RETURN VAR VAR FUNC_DEF IF VAR VAR RETURN ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN ASSIG...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: if n > m: self.tilingRectangle(m, n) self.ans = n * m h = [0] * n self.dfs(h, 0, n, m) return self.ans def dfs(self, h, cur, n, m): if cur >= self.ans: return min_h...
CLASS_DEF FUNC_DEF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR RETURN VAR VAR FUNC_DEF IF VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR V...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: dp = {} if n < m: m, n = n, m if m == n: return 1 res = [m * n + 1] def dfs(ys, cnt): key = tuple(ys) if key not in dp or cnt < dp[key]: dp[key]...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR LIST BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER RETURN IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FUNC_...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: if m == n: return 1 if n < m: m, n = n, m if m == 1: return n if m == 2: k, rem = divmod(n, 2) return k + 2 * rem def recurse(h, ct): no...
CLASS_DEF FUNC_DEF VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER RETURN VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER RETURN BIN_OP VAR BIN_OP NUMBER VAR FUNC_DEF IF VAR VAR RETURN IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN ASSIGN VAR VAR FUNC...
Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares are necessary to cover the rectangle. 2 (squares of 1x1) 1 (square of 2x2) Example 2: Input: n = 5, m = 8 Output: 5 Example 3: Input: n = 11, m...
class Solution: def tilingRectangle(self, n: int, m: int) -> int: self.best = n * m def dp(heights, n_square): if n_square > self.best: return if heights == [n] * m: self.best = min(self.best, n_square) min_index = min(range(m), k...
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_DEF IF VAR VAR RETURN IF VAR BIN_OP LIST VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR ...
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers. Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order. Example 1: Input: n = 3 Output: 3 2 1 1 1 1 Exp...
class Solution: def UniquePartitions(self, n): def helper(n, x, l, temp): if x == n: temp.append(l) return if x > n: return for i in range(n, 0, -1): if len(l) == 0 or l[-1] >= i: helper...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR LIST VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER LIST VAR RETURN VAR
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers. Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order. Example 1: Input: n = 3 Output: 3 2 1 1 1 1 Exp...
class Solution: def UniquePartitions(self, n): arr = [] for i in range(n, 0, -1): arr.append(i) res = [] def finder(arr, target, ind, path): if target == 0: res.append(path) return if ind == len(arr): ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN IF VAR FUNC_CALL VAR VAR RETURN IF VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN...
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers. Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order. Example 1: Input: n = 3 Output: 3 2 1 1 1 1 Exp...
class Solution: def UniquePartitions(self, n): li = [] def solve(i, target, li, temparr): if i <= 0: if target == 0: li.append(temparr[:]) return if target > 0: temparr.append(i) solve(i, ta...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR LIST RETURN VAR
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers. Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order. Example 1: Input: n = 3 Output: 3 2 1 1 1 1 Exp...
import sys sys.setrecursionlimit(1000000) def f(t, temp, res, last, N): if t == 0: c = temp[:] c.sort(reverse=True) res.append(c) return for i in range(last, n + 1): if i <= t: temp.append(i) f(t - i, temp, res, i, n) temp.pop() cl...
IMPORT EXPR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_C...
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers. Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order. Example 1: Input: n = 3 Output: 3 2 1 1 1 1 Exp...
class Solution: def UniquePartitions(self, n): arr = [i for i in range(n, 0, -1)] li = [] def solve(i, target, arr, li, temparr): if i >= len(arr): if target == 0: li.append(temparr[:]) return if target > 0: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR V...
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers. Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order. Example 1: Input: n = 3 Output: 3 2 1 1 1 1 Exp...
def backtracking(n): total = n stack = [] res = [] helper(n, total, stack, res) return res def helper(n, total, stack, res): if not total: res.append(tuple(stack)) for i in range(n, 0, -1): if total - i >= 0 and not stack: stack.append(i) helper(n, t...
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF B...
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers. Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order. Example 1: Input: n = 3 Output: 3 2 1 1 1 1 Exp...
class Solution: def __init__(self): self.ans = [] def f(self, W, n, arr, temp): if W == 0: self.ans.append(temp[0:]) return if n < 0: return if arr[n] <= W: temp.append(arr[n]) Solution.f(self, W - arr[n], n, arr, temp...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER RETURN IF VAR NUMBER RETURN IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUN...
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers. Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order. Example 1: Input: n = 3 Output: 3 2 1 1 1 1 Exp...
class Solution: def UniquePartitions(self, n): dp = [(0) for i in range(n)] count = 0 ar = [] def solve(remSum, maxVal, idx, count): if remSum == 0: a = [] for i in range(idx): a.append(dp[i]) ar.append...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN ASSIGN VAR VAR WHILE VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_...
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers. Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order. Example 1: Input: n = 3 Output: 3 2 1 1 1 1 Exp...
class Solution: def firstApproach(self, n): p = [0] * n k = 0 p[k] = n res = [] while True: res.append(p[0 : k + 1]) rem_val = 0 while k >= 0 and p[k] == 1: rem_val += p[k] k -= 1 if k < 0: ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR LIST WHILE NUMBER EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR NUMBER RETURN VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR ASSIGN VAR ...
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers. Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order. Example 1: Input: n = 3 Output: 3 2 1 1 1 1 Exp...
class Solution: def duplicate(self, lt): k = [] for i in lt: if i not in k: k.append(i) return k def lexsort(self, lt): lt = sorted(lt, reverse=True) return lt def UniquePartitions(self, n): dict1 = {(1): [[1]]} for i in ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR DICT NUMBER LIST LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR LIST EXPR FUNC_CALL VAR VAR LIST VAR FOR VAR FUNC_CALL VAR BI...
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers. Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order. Example 1: Input: n = 3 Output: 3 2 1 1 1 1 Exp...
class Solution: def helper(self, n, prev, current): if n == 0: self.finalAns.append(current[:]) return for i in range(min(prev, n), 0, -1): current.append(i) self.helper(n - i, i, current) current.pop() def UniquePartitions(self, n): ...
CLASS_DEF FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR FUNC_CALL VAR STRING LIST RETURN VAR
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers. Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order. Example 1: Input: n = 3 Output: 3 2 1 1 1 1 Exp...
class Solution: def UniquePartitions(self, n): table = [None] * (n + 1) table[0] = [] table[1] = [[1]] for i in range(2, n + 1): res = [[i]] for j in range(i, 0, -1): for k in table[i - j]: if j >= k[0]: ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER ASSIGN VAR NUMBER LIST ASSIGN VAR NUMBER LIST LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST LIST VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR BIN_OP VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST VAR VAR A...
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers. Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order. Example 1: Input: n = 3 Output: 3 2 1 1 1 1 Exp...
class Solution: def solve(self, remSum, maxVal, idx, count, ans, dp): if remSum == 0: part = [] for i in range(1, idx, 1): part.append(dp[i]) ans.append(part) count += 1 return i = maxVal while i >= 1: i...
CLASS_DEF FUNC_DEF IF VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN ASSIGN VAR VAR WHILE VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER ...
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers. Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order. Example 1: Input: n = 3 Output: 3 2 1 1 1 1 Exp...
class Solution: def UniquePartitions(self, n): dp = [[[1 + i]] for i in range(n)] for i in range(1, n): for j in range(i): dp[i] += [ ([i - j] + partition) for partition in dp[j] if partition[0] <= i - j ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST LIST BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP LIST BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER BIN_OP VAR VAR RETURN VAR BIN_OP VAR NUMBER
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers. Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order. Example 1: Input: n = 3 Output: 3 2 1 1 1 1 Exp...
class Solution: def UniquePartitions(self, n): seq = [i for i in range(1, n + 1)] ans = [] cur = [] def partition(num, seq, n): nonlocal ans, cur if num == 0: for i in cur: ans.append([i]) return ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR LIST VAR RETURN IF VAR NUMBER RETURN IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBE...
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers. Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order. Example 1: Input: n = 3 Output: 3 2 1 1 1 1 Exp...
class Solution: def UniquePartitions(self, n): res = [] nums = [i for i in range(1, n + 1)] def solve(target, n, arr): if target == 0: if arr not in res: res.append(arr) return if n < 0: return ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR NUMBER RETURN IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR V...
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers. Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order. Example 1: Input: n = 3 Output: 3 2 1 1 1 1 Exp...
class Solution: def UniquePartitions(self, n): all_p = [] def partition(k, m, parts): if k == 0: return parts return_parts = [] for j in range(min(k, m), 0, -1): next_parts = parts.copy() next_parts.append(j) ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR ...
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers. Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order. Example 1: Input: n = 3 Output: 3 2 1 1 1 1 Exp...
class Solution: def UniquePartitions(self, n): def fun(l, i, n): if n == 0: l1.append(l.copy()) return l1 if i < 1: return l1 if i <= n: l.append(i) fun(l, i, n - i) l.pop() ...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN VAR IF VAR NUMBER RETURN VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR LIST ASSIGN V...
Given a positive integer n, generate all possible unique ways to represent n as sum of positive integers. Note: The generated output is printed without partitions. Each partition must be in decreasing order. Printing of all the partitions is done in reverse sorted order. Example 1: Input: n = 3 Output: 3 2 1 1 1 1 Exp...
def rec(n, j): if n == 0: return [[]] c = [] for i in range(1, j + 1): if n >= i: ans = rec(n - i, i) for k in ans: c.append([i] + k) return c class Solution: def UniquePartitions(self, n): res = rec(n, n) res.sort(reverse=Tr...
FUNC_DEF IF VAR NUMBER RETURN LIST LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST VAR VAR RETURN VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN VAR