description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not. Example 1: Input: n = 3, m = 3, x = 62 matrix[][] = {{ 3, 30, 38}, {36, 43, 60}, {40, 51, 69}} Output: 0 Explanation: 62 is not pres...
class Solution: def search(self, arr, n, m, x): r = n - 1 c = 0 while r > -1 and c < m: ele = arr[r][c] if ele == x: return True elif x > ele: c += 1 elif x < ele: r -= 1 return False
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER RETURN NUMBER
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not. Example 1: Input: n = 3, m = 3, x = 62 matrix[][] = {{ 3, 30, 38}, {36, 43, 60}, {40, 51, 69}} Output: 0 Explanation: 62 is not pres...
class Solution: def search(self, matrix, n, m, x): def binary_search(arr, key): l = 0 r = len(arr) - 1 while l <= r: mid = (l + r) // 2 if arr[mid] == key: return 1 elif arr[mid] > key: ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER...
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not. Example 1: Input: n = 3, m = 3, x = 62 matrix[][] = {{ 3, 30, 38}, {36, 43, 60}, {40, 51, 69}} Output: 0 Explanation: 62 is not pres...
class Solution: def search(self, matrix, n, m, x): l = [] for i in range(n): l += matrix[i] try: v = l.index(x) i = 1 except ValueError: i = 0 return i
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER RETURN VAR
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not. Example 1: Input: n = 3, m = 3, x = 62 matrix[][] = {{ 3, 30, 38}, {36, 43, 60}, {40, 51, 69}} Output: 0 Explanation: 62 is not pres...
class Solution: def search(self, matrix, n, m, x): t = [] r = [] for i in range(len(matrix)): t = matrix[i] for j in range(len(t)): r.append(t[j]) if x in r: return True return False
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not. Example 1: Input: n = 3, m = 3, x = 62 matrix[][] = {{ 3, 30, 38}, {36, 43, 60}, {40, 51, 69}} Output: 0 Explanation: 62 is not pres...
class Solution: def search(self, a, n, m, x): k, l = 0, m - 1 while k < n - 1 and l >= 0: if a[k][l] > x: l -= 1 elif a[k][l] < x: k += 1 else: return True return False
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER
Given a matrix of size n x m, where every row and column is sorted in increasing order, and a number x. Find whether element x is present in the matrix or not. Example 1: Input: n = 3, m = 3, x = 62 matrix[][] = {{ 3, 30, 38}, {36, 43, 60}, {40, 51, 69}} Output: 0 Explanation: 62 is not pres...
class Solution: def search(self, matrix, r, c, x): l, d = c - 1, 0 while l >= 0 and d <= r - 1: if matrix[l][d] == x: return 1 elif matrix[l][d] < x: d += 1 else: l -= 1 return 0
CLASS_DEF FUNC_DEF ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: possibilities = set() def swap(arr, l, r): if l == r: return arr[l], arr[r] = arr[r], arr[l] def add_permutation(arr): nonlocal possibilities for i in range(l...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR BIN_OP VAR NUMBER FUNC_DEF NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FU...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: def recur(tiles): if not tiles: return set() ans = set() for i, v in enumerate(tiles): ans.add(v) new = recur(tiles[:i] + tiles[i + 1 :]) a...
CLASS_DEF FUNC_DEF VAR FUNC_DEF IF VAR RETURN FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: def freq(tiles): d = {} for c in tiles: if c in d: d[c] += 1 else: d[c] = 1 return d def build(d, s): new_d = ...
CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_C...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: result = set() def dfs_helper(path, t): if path: result.add(path) for i in range(len(t)): dfs_helper(path + t[i], t[:i] + t[i + 1 :]) dfs_helper("", tiles) re...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING VAR RETURN FUNC_CALL VAR VAR VAR
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: setter = set() res = [] for r in range(1, len(tiles) + 1): res.append(list(itertools.permutations(tiles, r))) result = [] for re in res: result.append(list(set(re))) leng = 0 ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR RETURN VA...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: def dfs(state): res.append(state.copy()) for i in range(len(state)): if state[i] < full_state[i]: state[i] += 1 dfs(state) state[i] -= 1 ...
CLASS_DEF FUNC_DEF VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR ...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def __init__(self): self.seen = set() self.result = set() def numTilePossibilities(self, tiles: str) -> int: self.dfs(tiles, 0, []) return len(self.result) - 1 def dfs(self, string, idx, path): st = "".join(path) if st not in self.seen: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF VAR EXPR FUNC_CALL VAR VAR NUMBER LIST RETURN BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL STRING VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR V...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: d = {} for i in range(len(tiles)): if tiles[i] in d: d[tiles[i]] += 1 else: d[tiles[i]] = 1 def countnum(d): if d == {}: return 0 ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FUNC_DEF IF VAR DICT RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR ...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: @lru_cache(None) def find(s): if len(s) <= 1: return set([s]) ret = set() for i in range(len(s)): head = s[i] tails = find(s[:i] + s[i + 1 :]) ...
CLASS_DEF FUNC_DEF VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR LIST VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR ...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: result = set() vis = [0] * len(tiles) def dfs(res, depth): if res: result.add(res) if depth == len(tiles) - 1: result.add(res) for i in range(len(tiles)): ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FUNC_DEF IF VAR EXPR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR N...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def __init__(self): self.total = 0 self.string = [] self.dict_ = {} self.arr = [] self.n = 0 def perm(self): if self.n == len(self.string): self.total += 1 for i in range(len(self.arr)): if self.arr[i][1] > 0: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR NUMBE...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: output = set() def helper(result, options): if not options: return for idx, o in enumerate(options): tmp = options[:] tmp.pop(idx) output.add("...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR RETURN FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR LIST VAR EXPR FUNC_CALL VAR BIN_OP VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
def possible(tiles): variants = set() if len(tiles) == 1: variants.add(tiles[0]) else: for i in range(len(tiles)): t = possible(tiles[:i] + tiles[i + 1 :]) variants.update(t) for j in t: variants.add(tiles[i] + j) return variants clas...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN VAR CLASS_DEF FUNC_DEF VAR RETURN FUNC_CALL VA...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: result = set() maxx = len(tiles) def dfs(result, tiles, current_sequence=""): result.add(current_sequence) for t in tiles: tiles_c = tiles.replace(t, "", 1) dfs(result...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF STRING EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER VAR
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: memos = dict() def numTilePossibilities(self, tiles: str) -> int: tiles = "".join(sorted(tiles)) uniques = self.step(tiles) return len(uniques) - 1 def step(self, tiles: str) -> set: if len(tiles) == 0: return {""} if tiles not in self.me...
CLASS_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_DEF VAR IF FUNC_CALL VAR VAR NUMBER RETURN STRING IF VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSI...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: count = {} for i in tiles: if i not in count: count[i] = 0 count[i] += 1 op = set() for ch in count: tempString = ch op.add(tempString) coun...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR ...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: def backtrack(i, c): if i == n: return for k in c: if c[k] > 0: self.ans += 1 backtrack(i + 1, c - Counter(k)) n = len(tiles) ...
CLASS_DEF FUNC_DEF VAR FUNC_DEF IF VAR VAR RETURN FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR RETURN VAR VAR
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: d = set() for i in range(len(tiles)): for x in list(permutations(tiles, i + 1)): d.add("".join(x)) print(d) return len(d)
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def subsets(self, tiles, buff, buff_index, boolean, s): if tuple(buff[:buff_index]) not in s: s.add(tuple(buff[:buff_index])) self.count += 1 if len(buff) == buff_index: return for i in range(0, len(tiles)): if not boolean[i]: ...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR RETURN FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER FUNC_DEF V...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: def perm(k, a): if k == 0: return [] elif k == 1: return [x for x in a] else: return [ (a[i] + y) for i in range(le...
CLASS_DEF FUNC_DEF VAR FUNC_DEF IF VAR NUMBER RETURN LIST IF VAR NUMBER RETURN VAR VAR VAR RETURN BIN_OP VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR ...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: def next_permutation(a): for i in range(len(a) - 1, 0, -1): if a[i] > a[i - 1]: ps = i for j in range(i + 1, len(a)): if a[j] > a[i - 1] and a[ps] ...
CLASS_DEF FUNC_DEF VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VA...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: words = set() curr = "" tile_count = {} for x in tiles: if x not in tile_count: tile_count[x] = 0 tile_count[x] += 1 def walk(curr, tiles, words): for tile...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FUNC_DEF FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR EXPR FU...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def __init__(self): self.res = set() def backtrack(self, tiles, curr, indices): for i in range(len(tiles)): if i not in set(indices): curr += tiles[i] indices.append(i) self.res.add(curr) if len(curr) <...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_DEF VAR EXPR FUNC_CALL VAR V...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, s: str) -> int: ans, C = 0, Counter(s) def dfs(C, cur): nonlocal ans if cur: ans += 1 if not C: return C1 = C.copy() for x in C: cur.append(x) ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR NUMBER IF VAR RETURN ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR LIST RETURN VAR VAR
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: combination_set = self.generateTilePossibilities(tiles) return len(combination_set) def generateTilePossibilities(self, tiles: str): n = len(tiles) combination_set = set() for index in range(n): ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
from itertools import permutations class Solution: def numTilePossibilities(self, tiles: str) -> int: total = 0 for size in range(1, len(tiles) + 1): total += len(set(permutations(tiles, size))) return total
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def get_permute(self, opts, cur_sol): for i in range(len(opts)): c = opts[i] cur_sol.append(c) self.solutions.add("".join(cur_sol)) opts2 = opts opts2 = opts2[:i] + opts2[i + 1 :] self.get_permute(opts2, cur_sol) ...
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR LIST RETU...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: pos = set() def choose(s, n, pref=""): if n == 0: pos.add(pref) for i in range(len(s)): choose(s[:i] + s[i + 1 :], n - 1, pref + s[i]) for i in range(1, len(tiles) + ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VA...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: res = set() def seq(s, l): if len(l) == 0: res.add(s) return seq(s, l[1:]) for i in range(len(l)): seq(s + l[i], l[:i] + l[i + 1 :]) seq("...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING FUNC_CALL VAR VAR RETURN BIN_O...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: res = 0 freqs = [(f + 1) for f in Counter(tiles).values()] for t in itertools.product(*map(range, freqs)): n = sum(t) subtotal = math.factorial(n) for freq in t: subtotal /...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN BIN_OP VAR NUMBER VAR
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: def dfs(elements): if prev_elements: result.add("".join(prev_elements)) for e in elements: next_elements = elements[:] next_elements.remove(e) prev_ele...
CLASS_DEF FUNC_DEF VAR FUNC_DEF IF VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FOR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def counts(self, collect): answer = 1 for char in collect: if collect[char]: answer += self.counts(collect - collections.Counter(char)) return answer def numTilePossibilities(self, c): return self.counts(collections.Counter(c)) - 1
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: def backtracking(idx=0, seq="", remaining=tiles): for i, tile in enumerate(remaining): res.add(seq + tile) backtracking(idx + 1, seq + tile, remaining[:i] + remaining[i + 1 :]) res = set...
CLASS_DEF FUNC_DEF VAR FUNC_DEF NUMBER STRING VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR VAR
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: result = 0 def numTilePossibilities(self, tiles: str) -> int: counter = Counter(tiles) self.dfs(counter, []) return self.result def dfs(self, counter, curr): if curr: self.result += 1 for x in counter: curr1 = curr.copy() ...
CLASS_DEF ASSIGN VAR NUMBER FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR LIST RETURN VAR VAR FUNC_DEF IF VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: def recur(tiles): if not tiles: return set() ans = set() temp = "" while tiles: v = tiles[0] ans.add(v) new = recur(temp + tile...
CLASS_DEF FUNC_DEF VAR FUNC_DEF IF VAR RETURN FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING WHILE VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VA...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: def count(tiles): counter = set() if len(tiles) == 1: counter.add(tiles) elif len(tiles) == 2: counter.add(tiles) counter.add(tiles[::-1]) ...
CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR V...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: return len( set( x for i in range(1, len(tiles) + 1) for x in itertools.permutations(tiles, i) ) )
CLASS_DEF FUNC_DEF VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: ans = 0 s = set() def tot(curr, rem): nonlocal s if curr[-1]: s.add(tuple(curr[-1])) for i in range(len(rem)): el = curr[-1] if rem[i] == e...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR LIST BIN_OP VAR LIST VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: tiles = "".join(sorted(tiles)) memo = {} def helper(s, k): if (s, k) not in memo: if k == 0: memo[s, k] = 1 else: last, ans = "", 0 ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR STRING NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NU...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: def helper(curr, tiles): for i in range(len(tiles)): curr.append(tiles[i]) pos.add(str(curr)) c = tiles.copy() c.pop(i) helper(curr.copy(), c) ...
CLASS_DEF FUNC_DEF VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VA...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def poss(self, tiles: str) -> set: if len(tiles) == 1: return set([tiles[0]]) output = set() for i in range(len(tiles)): elem = tiles[i] res = self.poss(tiles[:i] + tiles[i + 1 :]) output = output.union(res) for ele...
CLASS_DEF FUNC_DEF VAR IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR LIST VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN ...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: if len(tiles) < 2: return len(tiles) nodes = [] for letter in tiles: nodes.append(Node(letter)) for node in nodes: for other_node in nodes: if node != other_node: ...
CLASS_DEF FUNC_DEF VAR IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR R...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: result = set() def backtrack(left_tiles, curr_seq): if len(curr_seq) == k: result.add("".join(curr_seq)) return else: for i in range(len(left_tiles)): ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def make_tile(self, curr, used, letters, size): if len(curr) == size: self.res += 1 return i = 0 while i < len(letters): if i not in used: used.add(i) curr.append(letters[i]) self.make_tile(c...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR VAR VAR NUMBER RETURN ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NU...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: def solve(s, visited): seen.add(s) if len(s) == len(tiles): return 0 for i, v in enumerate(tiles): if i not in visited: solve(s + v, visited | {i}) ...
CLASS_DEF FUNC_DEF VAR FUNC_DEF EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR RETURN BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR NUMBER VAR
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: seen = set() ans = set() def backtrack(tiles, seen, curr): if curr != "" and curr not in ans: ans.add(curr) for i in range(len(tiles)): if i not in seen: ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR STRING VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING RETURN FUNC_CALL...
You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.   Example 1: Input: tiles = "AAB" Output: 8 Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA...
class Solution: def numTilePossibilities(self, tiles: str) -> int: tile_counts = collections.Counter(tiles) len_counts = [1] + [0] * len(tiles) for tile in tile_counts: new_len_counts = [0] * (len(tiles) + 1) num_tiles = tile_counts[tile] for num_inserted...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR FUNC_...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
n = int(input()) l = list(map(int, input().split())) q = int(input()) d = {} for i in range(n): item = l[i] for j in range(i, n): item = min(item, l[j]) if item in d: d[item] += 1 else: d[item] = 1 for i in range(q): k = int(input()) if k in d.keys(): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
n = int(input()) l = list(map(int, input().split())) q = int(input()) for _ in range(q): cnt = 0 k = int(input()) for i in range(n): for j in range(i, n): if min(l[i : j + 1]) == k: cnt += 1 print(cnt)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR ...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
n = int(input()) a = list(map(int, input().split())) d = {} for i in range(n): d[a[i]] = 0 for i in range(n): for j in range(i, n): l = a[i : j + 1] d[min(l)] += 1 q = int(input()) for _ in range(q): x = int(input()) if x in d: print(d[x]) else: print(0)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
n = int(input()) arr = [int(i) for i in input().split()] p = sorted(arr) mn = p[0] mx = p[-1] for i in range(int(input())): k = int(input()) if k < mn or k > mx: print(0) else: ans = 0 for i in range(n): c_r = 0 c_l = 0 if arr[i] == k: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
n = int(input()) A = list(map(int, input().strip().split())) D = dict() for l in range(len(A)): for r in range(l + 1, len(A) + 1): v = min(A[l:r]) D[v] = 1 if not v in D else D[v] + 1 q = int(input()) for i in range(q): v = int(input()) print(0 if not v in D else D[v])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
array_size = int(input()) arr = input().split(" ") arr = list(map(int, arr)) query_no = int(input()) for tc in range(query_no): k = int(input()) count = 0 result = [[]] for i in range(len(arr) + 1): for j in range(i + 1, len(arr) + 1): sub = arr[i:j] result.append(sub) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NU...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
N = int(input()) A = [int(x) for x in input().split()] for _ in range(int(input())): K = int(input()) total = 0 for i in range(N): a = 0 count = 0 forward = 0 backward = 1 if A[i] == K: if i != A.index(K): a = 1 for j in range(i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR IF V...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
n = int(input()) a = [int(word) for word in input().split()] q = int(input()) for iq in range(q): k = int(input()) ways = 0 last_lt = -1 last_leq = -1 for i in range(n): if a[i] < k: last_lt = i if a[i] <= k: last_leq = i ways += last_leq - last_lt ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
def solve(a, k): listOfMin = [] length = len(a) for i in range(length): for j in range(i + 1, length + 1): listOfMin.append(min(a[i:j])) count = 0 for e in listOfMin: if e == k: count += 1 return count sizeOfArray = int(input()) a = [] elements = input()...
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CAL...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
n = int(input()) l = list(map(int, input().split())) d = {} for i in range(n): a = [] x = l[i] for j in range(i, n): a.append(l[j]) x = min(x, l[j]) if x in d: d[x] += 1 else: d[x] = 1 q = int(input()) while q > 0: b = int(input()) if b in d: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NU...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
input() arr = list(map(int, input().split())) Q = int(input()) for item in range(Q): K = int(input()) total = 0 for i in range(len(arr)): hasK = False if arr[i] >= K: if arr[i] == K: hasK = True total += 1 j = i + 1 while j ...
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER VAR NU...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
t = 1 for _ in range(t): n = int(input()) l = list(map(int, input().split())) d = {} for i in range(n): k = l[i] for j in range(i, n): k = min(k, l[j]) try: d[k] += 1 except: d[k] = 1 q = int(input()) for _ in ra...
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIG...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
import itertools import sys def solve(N, A, K): count_sets = lambda g, i: (i + 1) * (len(g) - i) groups = [list(g) for k, g in itertools.groupby(A, lambda x: x >= K) if k] total = 0 for g in groups: if g.count(K) > 0: idx = [i for i, a in enumerate(g) if a == K] for i i...
IMPORT IMPORT FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR ...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
n = int(input()) arr = list(map(int, input().split())) q = int(input()) for i in range(q): num = int(input()) ans = 0 for j in range(n): if arr[j] == num: temp = 1 count = 1 for k in range(j + 1, n): if min(num, arr[k]) == num: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CA...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
def sub(arr, k, f, n): i = j = d u = v = 0 i -= 1 j += 1 flag = 0 while i > -1: if arr[i] < k: break if arr[i] == k: flag = 1 break u += 1 i -= 1 while j < n: if arr[j] < k: break v += 1 j...
FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP VAR...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
N = int(input()) A = list(map(int, input().split())) Q = int(input()) pre = [(1) for i in range(N)] post = [(1) for i in range(N)] for i in range(N): count = 0 k = 1 while i + k < N and A[i] <= A[i + k]: count += 1 k += 1 pre[i] += count for i in range(N - 1, -1, -1): count = 0 k...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR ...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
n = int(input()) a = list(map(int, input().split())) cnt = {} left = [1] stack = [[a[0], 1]] for i in range(1, n): curr = 0 while True: if len(stack) == 0: curr = i break if stack[-1][0] > a[i]: curr += stack.pop()[1] else: break stack....
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST NUMBER ASSIGN VAR LIST LIST VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER WHILE NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER NUMBER VAR VAR ...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
n = int(input()) A = list(map(int, input().split())) k = int(input()) B = [0] * (max(A) + 1) for i in range(n): y = A[i] for j in range(i, n): y = min(y, A[j]) B[y] += 1 for _ in range(k): Q = int(input()) if Q in A: print(B[Q]) else: print(0)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR V...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
import sys t = int(sys.stdin.readline()) a = [] m = [] a = [int(x) for x in input().split()] q = int(sys.stdin.readline()) for y in range(q): m.append(int(sys.stdin.readline())) for x in m: c = 0 for i in range(t): for j in range(i + 1, t + 1): if x == min(a[i:j]): c += ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
n = int(input()) A = list(map(int, input().split())) B = [] for i in range(n): x = A[i] for j in range(i, n): x = min(x, A[j]) B.append(x) q = int(input()) for i in range(q): k = int(input()) print(B.count(k))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VA...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
n = int(input()) lis = list(map(int, input().split())) q = int(input()) ans = [] res = [] for i in range(len(lis) + 1): ans = [] for j in range(i + 1, len(lis) + 1): ans = lis[i:j] res.append(ans) while q > 0: k = int(input()) count = 0 for i in range(len(res)): if k == min(r...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER A...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
n = int(input()) arr = input().split() arr = [int(x) for x in arr] q = int(input()) while q: q -= 1 ans = 0 k = int(input()) for i in range(n): temp = arr[i] for j in range(i, n): temp = min(temp, arr[j]) ans += int(temp == k) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_C...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
def cal_temp_subarr(start, end, q_pos): temp = (q_pos[0] - start + 1) * (end - q_pos[0]) for i in range(1, len(q_pos)): temp += (q_pos[i] - q_pos[i - 1]) * (end - q_pos[i]) return temp n = int(input()) arr = list(map(int, input().split())) q = int(input()) for i in range(q): num = int(input())...
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSI...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
n = int(input()) s1 = input().split(" ") l = [] for _ in s1: l.append(int(_)) i = 0 sub = [] while i < n: s = i f = i + 1 while f <= n: l1 = l[s:f] sub.append(l1) f += 1 i += 1 q = int(input()) k = 0 while k < q: c = 0 q1 = int(input()) for e in sub: if mi...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
n = int(input()) al = [int(num) for num in input().split(" ", n - 1)] for k in range(int(input())): cnt = 0 val = int(input()) for i in range(n): for j in range(i, n): sb = al[i : j + 1] if min(sb) == val: cnt += 1 print(cnt)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
n = int(input()) arr = [int(i) for i in input().split()] q = int(input()) for _ in range(q): val = int(input()) if val not in arr: print(0) else: count = 0 for i in range(1, n + 1): for j in range(n - i + 1): if min(arr[j : j + i]) == val: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL ...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
t = int(input()) a = list(map(int, input().split())) q = int(input()) for i in range(q): n = int(input()) count = 0 for j in range(t): c = [] for k in range(j, t): c.append(a[k]) if min(c) == n: count += 1 print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR V...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
input() arr = list(map(int, input().split(" "))) subarrays = [] temp_arr = [] for i in range(len(arr) - 1): for j in range(i, len(arr)): temp_arr.append(arr[j]) subarrays.append(temp_arr.copy()) temp_arr = [] subarrays.append([arr[-1]]) for query in range(int(input())): num = int(input()) ...
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR LI...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
def getCount(n, ar, lo): count = 0 for i in range(0, n): for j in range(i, n): sub = ar[i : j + 1] if min(sub) == lo: count += 1 return count nOEl = int(input()) aOEl = [int(x) for x in input().split()] queC = int(input()) while queC != 0: k = int(input(...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR N...
Little Elephant is playing a game with arrays. He is given an array A0, A1, ..., AN−1 of N integers. And then Q queries are given, each containing an integer K. He has to tell how many subarrays satisfy the condition: the function foo returns K when it is applied to the subarray. In this problem, a subarray is defined...
def left(a, pos): current = a[pos] counter = 1 pos -= 1 while 1: if pos < 0: break if current >= a[pos]: break else: counter += 1 pos -= 1 return counter def right(a, pos): current = a[pos] counter = 1 pos += 1 whi...
FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER WHILE NUMBER IF VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER WHILE NUMBER IF VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING...
An encoded string (s) is given, and the task is to decode it. The encoding pattern is that the occurrence of the string is given at the starting of the string and each string is enclosed by square brackets. Note: The occurance of a single string is less than 1000. Example 1: Input: s = 1[b] Output: b Explaination: 'b' ...
class Solution: def decodedString(self, s): num = "" z = [] res = "" stack = [] for i in s: if i.isdigit(): num += i elif i == "[" or i.isalpha(): stack.append(i) if len(num): z.appen...
CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR VAR IF VAR STRING FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF VAR ASSIGN VAR STRING WHILE VAR NUMBER STRING ASSIGN VAR BIN_OP FU...
An encoded string (s) is given, and the task is to decode it. The encoding pattern is that the occurrence of the string is given at the starting of the string and each string is enclosed by square brackets. Note: The occurance of a single string is less than 1000. Example 1: Input: s = 1[b] Output: b Explaination: 'b' ...
class Solution: def decodedString(self, s): st = [] for i in s: if i != "]": st.append(i) else: res = "" while st[-1] != "[": res = st.pop() + res st.pop() temp = "" ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING WHILE VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR STRING WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER A...
An encoded string (s) is given, and the task is to decode it. The encoding pattern is that the occurrence of the string is given at the starting of the string and each string is enclosed by square brackets. Note: The occurance of a single string is less than 1000. Example 1: Input: s = 1[b] Output: b Explaination: 'b' ...
class Solution: def decodedString(self, s): l = list(s) iStack = [] cStack = [] st = "" sta = "" nmString = "" for i in l: if i.isnumeric(): nmString = nmString + i if i.isalpha() or i == "[": if nmStrin...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR STRING IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR ...
An encoded string (s) is given, and the task is to decode it. The encoding pattern is that the occurrence of the string is given at the starting of the string and each string is enclosed by square brackets. Note: The occurance of a single string is less than 1000. Example 1: Input: s = 1[b] Output: b Explaination: 'b' ...
class Solution: def decodedString(self, s): stack = [] curNum = 0 curStr = "" for i in s: if i == "[": stack.append(curStr) stack.append(curNum) curStr = "" curNum = 0 elif i == "]": ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_O...
An encoded string (s) is given, and the task is to decode it. The encoding pattern is that the occurrence of the string is given at the starting of the string and each string is enclosed by square brackets. Note: The occurance of a single string is less than 1000. Example 1: Input: s = 1[b] Output: b Explaination: 'b' ...
class Stack: def __init__(self, size): self.stack = [0] * size self.end = -1 def isEmpty(self): if self.end == -1: return True else: return False def push(self, value): self.end += 1 self.stack[self.end] = value def pop(self): ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF VAR NUMBER ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIG...
An encoded string (s) is given, and the task is to decode it. The encoding pattern is that the occurrence of the string is given at the starting of the string and each string is enclosed by square brackets. Note: The occurance of a single string is less than 1000. Example 1: Input: s = 1[b] Output: b Explaination: 'b' ...
class Solution: def decodedString(self, s): x = [] for i in range(len(s)): if s[i] != "]": x.append(s[i]) else: a = "" while x[-1] != "[" and len(x) > 0: a = x.pop() + a x.pop() ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING WHILE VAR NUMBER STRING FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR STRING WHILE FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN V...
An encoded string (s) is given, and the task is to decode it. The encoding pattern is that the occurrence of the string is given at the starting of the string and each string is enclosed by square brackets. Note: The occurance of a single string is less than 1000. Example 1: Input: s = 1[b] Output: b Explaination: 'b' ...
class Solution: def decodedString(self, s): l = [] n = len(s) for i in range(n): if s[i] == "]": s1 = "" while l[len(l) - 1] != "[": s1 += l[len(l) - 1] l.pop() l.pop() s1 = s...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR STRING WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR STRING WHILE FUNC_CALL VAR VAR NUM...
An encoded string (s) is given, and the task is to decode it. The encoding pattern is that the occurrence of the string is given at the starting of the string and each string is enclosed by square brackets. Note: The occurance of a single string is less than 1000. Example 1: Input: s = 1[b] Output: b Explaination: 'b' ...
class Solution: def decodedString(self, s): ans = "" stack = list() s = s[::-1] n = len(s) i = 0 while i < n: if s[i].isnumeric(): if len(stack) and stack[-1] == "[": stack.pop() temp = "" ...
CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR ASSIGN VAR STRING WHILE FUNC_CALL VAR VAR VAR NUMBER STRING VAR FUNC_CALL VAR EXPR FUNC_CALL VAR...
An encoded string (s) is given, and the task is to decode it. The encoding pattern is that the occurrence of the string is given at the starting of the string and each string is enclosed by square brackets. Note: The occurance of a single string is less than 1000. Example 1: Input: s = 1[b] Output: b Explaination: 'b' ...
def rec(s): stack = [] for i in range(len(s)): if s[i] in "0123456789" or s[i] in "[": stack.append(s[i]) elif s[i] in "]": st = "" j = 0 k = -1 while stack[k] != "[": j = j + 1 k = k - 1 st =...
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR IF VAR VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR BIN_OP FUNC_...
An encoded string (s) is given, and the task is to decode it. The encoding pattern is that the occurrence of the string is given at the starting of the string and each string is enclosed by square brackets. Note: The occurance of a single string is less than 1000. Example 1: Input: s = 1[b] Output: b Explaination: 'b' ...
class Solution: def decodedString(self, s): charStack = [] number = 0 finalString = "" while s: st = "" if s[0] == "[": num = "" while charStack and charStack[-1].isdigit(): num = charStack.pop() + num ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE VAR ASSIGN VAR STRING IF VAR NUMBER STRING ASSIGN VAR STRING WHILE VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR V...
An encoded string (s) is given, and the task is to decode it. The encoding pattern is that the occurrence of the string is given at the starting of the string and each string is enclosed by square brackets. Note: The occurance of a single string is less than 1000. Example 1: Input: s = 1[b] Output: b Explaination: 'b' ...
class Solution: def decodedString(self, s): stack = [] for item in s: if item != "]": stack.append(item) else: substring = "" while stack[-1] != "[": substring = stack.pop() + substring stack...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING WHILE VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR STRING WHILE VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP...
An encoded string (s) is given, and the task is to decode it. The encoding pattern is that the occurrence of the string is given at the starting of the string and each string is enclosed by square brackets. Note: The occurance of a single string is less than 1000. Example 1: Input: s = 1[b] Output: b Explaination: 'b' ...
class Solution: def decodedString(self, s): num = "" nums = [] stack = [""] for item in s: if item.isdigit(): num += item elif item == "[": nums.append(int(num)) num = "" stack.append("") ...
CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST STRING FOR VAR VAR IF FUNC_CALL VAR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR STRING IF VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR RETURN VAR NUMBER
An encoded string (s) is given, and the task is to decode it. The encoding pattern is that the occurrence of the string is given at the starting of the string and each string is enclosed by square brackets. Note: The occurance of a single string is less than 1000. Example 1: Input: s = 1[b] Output: b Explaination: 'b' ...
class Solution: def decodedString(self, s): stack = [] i = 0 result = "" num = "" while i < len(s): if s[i] == "]": if stack[-1] == "[": stack.pop() result *= int(stack.pop()) stack.appen...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR NUMBER STRING EXPR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ...
An encoded string (s) is given, and the task is to decode it. The encoding pattern is that the occurrence of the string is given at the starting of the string and each string is enclosed by square brackets. Note: The occurance of a single string is less than 1000. Example 1: Input: s = 1[b] Output: b Explaination: 'b' ...
class Solution: def decodedString(self, s): stack = [] curstr = "" curdig = "" prevdig = "" prevstr = "" for i in range(len(s)): if s[i] == "[": stack.append(curstr) stack.append(curdig) curdig = "" ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIG...
An encoded string (s) is given, and the task is to decode it. The encoding pattern is that the occurrence of the string is given at the starting of the string and each string is enclosed by square brackets. Note: The occurance of a single string is less than 1000. Example 1: Input: s = 1[b] Output: b Explaination: 'b' ...
class Solution: def decodedString(self, s): cur_str = "" num = 0 stack = [] for i in s: if i.isdigit(): num = num * 10 + int(i) elif i.isalpha(): cur_str += i elif i == "[": stack.append((num, cur_st...
CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VA...
An encoded string (s) is given, and the task is to decode it. The encoding pattern is that the occurrence of the string is given at the starting of the string and each string is enclosed by square brackets. Note: The occurance of a single string is less than 1000. Example 1: Input: s = 1[b] Output: b Explaination: 'b' ...
class Solution: def decodedString(self, s): res = "" st = [] for i in range(len(s)): if s[i] == "]": temp = "" while st and st[-1] != "[": temp += st[-1] st.pop() st.pop() tem...
CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR STRING WHILE VAR VAR NUMBER STRING VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR STRING WHILE VAR FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUM...
An encoded string (s) is given, and the task is to decode it. The encoding pattern is that the occurrence of the string is given at the starting of the string and each string is enclosed by square brackets. Note: The occurance of a single string is less than 1000. Example 1: Input: s = 1[b] Output: b Explaination: 'b' ...
class Solution: def decodedString(self, s): numStack = [] strStack = [] num = 0 str = [] for c in s: if c.isdigit(): num = num * 10 + int(c) elif c == "[": strStack.append(str) numStack.append(num) ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSI...