description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): substrs = [] substr = "" chars = {} for c in s: substr += c if c in chars.keys(): chars[c] += 1 else: chars[c] = 1 if len(chars) == k: subs...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR DICT FOR VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBE...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): n = len(s) freq = [0] * 26 start = 0 distinct_count = 0 max_len = -1 for end in range(n): char_index = ord(s[end]) - ord("a") freq[char_index] += 1 if freq[char_index] == 1: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUN...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): return self.helper(s, k) def helper(self, s, k): i, j, ans = 0, 0, -1 state = {} N = len(s) for j in range(N): state[s[j]] = 1 + state.get(s[j], 0) while len(state) > k: state[s[i]] ...
CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VA...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): d = {} for i in range(len(s)): if s[i] in d: d[s[i]] += 1 else: d[s[i]] = 1 if len(d) < k: return -1 m = {} j = 0 ans = 0 for i in range(len(s)...
CLASS_DEF FUNC_DEF 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 IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR N...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): window_start, hash_map, max_len = 0, {}, 0 for window_end in range(len(s)): hash_map[s[window_end]] = 1 + hash_map.get(s[window_end], 0) while len(hash_map) > k: hash_map[s[window_start]] -= 1 if...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER DICT NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN FUNC...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): i = 0 result = -1 mapp = dict() for j, v in enumerate(s): mapp[v] = mapp.get(v, 0) + 1 if len(mapp) == k: total = 0 for val in mapp.values(): total += val ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF ...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): ans = float("-inf") curr = 0 startWindow = 0 mp = {} for endWindow in range(len(s)): if s[endWindow] not in mp: mp[s[endWindow]] = 1 else: mp[s[endWindow]] += 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, a, k): i, j = 0, 0 s = {} maxi = 0 n = len(a) while j < n: if a[j] in s: s[a[j]] += 1 else: s[a[j]] = 1 j += 1 while len(s) > k: s[a[i]] -...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): n = len(s) hashmap = {} l, r = 0, 0 res = 0 while r < n: while len(hashmap) > k: hashmap[s[l]] -= 1 if hashmap[s[l]] == 0: del hashmap[s[l]] l += 1...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): n = len(s) distinct = 0 length = 0 letters = {} i, j = 0, 0 while j < n: if s[j] in letters: letters[s[j]] += 1 else: letters[s[j]] = 1 distinct = len(...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR VAR V...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): count = 0 l = 0 r = 0 arr = {} maxx = 0 for i in range(len(s)): if s[i] not in arr: count += 1 arr[s[i]] = 1 else: arr[s[i]] += 1 if co...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUM...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): d = {} i = 0 answer = 0 for j in range(len(s)): d[s[j]] = d.get(s[j], 0) + 1 if len(d) < k: pass elif len(d) == k: answer = max(answer, j - i + 1) elif len...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR WHILE FUNC_CAL...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): hm = {} i = 0 result = -1 for j, val in enumerate(s): hm[val] = hm.get(val, 0) + 1 while len(hm) > k: hm[s[i]] -= 1 if hm[s[i]] == 0: del hm[s[i]] ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR V...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): i = 0 j = 0 dic = {} ans = -1 while j < len(s): if s[j] not in dic: dic[s[j]] = 1 else: dic[s[j]] += 1 if len(dic) < k: j += 1 elif...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL ...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): d = {} l = len(s) j = 0 mx = -1 for i in range(l): if s[i] not in d: d[s[i]] = 1 else: d[s[i]] = d[s[i]] + 1 while len(d) > k: d[s[j]] = d[s[j]...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR V...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def uniqChars(self, s): map = {} for i in s: map[i] = True return len(map.keys()) def longestKSubstr(self, s, k): freq = {} i, j = 0, 1 if self.uniqChars(s) < k: return -1 freq[s[0]] = 1 mxLen = 1 u...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): map = {} left = 0 maxLength = -1 for right in range(len(s)): ch = s[right] map[ch] = map.get(ch, 0) + 1 if len(map) == k: maxLength = max(maxLength, right - left + 1) whil...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VA...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): left = 0 freq = {} res = 0 for right, c in enumerate(s): freq[c] = freq.get(c, 0) + 1 if len(freq) == k: res = max(res, right - left + 1) while len(freq) > k: freq[s[l...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMB...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): hashmap = {} for i in s: hashmap[i] = 1 + hashmap.get(i, 0) if len(hashmap) < k: return -1 windowstart = 0 hashtable = {} length = 0 for windowend in range(len(s)): if s[windo...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR ...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): i = -1 j = -1 left = 0 right = 0 hm = {} while right < len(s): if s[right] not in hm: hm[s[right]] = 1 else: hm[s[right]] += 1 while left <= right and ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER WHILE VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): i, j = 0, 0 freq = {} ans = -1 while j < len(s): if s[j] in freq: freq[s[j]] += 1 else: freq[s[j]] = 1 if len(freq) < k: j += 1 elif len(fr...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER WHILE FUNC_CALL VAR ...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): occurences = {} count = k l = 0 r = 0 n = len(s) maxLen = -1 while r < n: occurences[s[r]] = occurences.get(s[r], 0) + 1 if occurences[s[r]] == 1: count -= 1 i...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): di = {} i = 0 j = 0 n = len(s) maxLen = 0 while j < n: if s[j] not in di: di[s[j]] = 1 else: di[s[j]] += 1 if len(di) < k: j += 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBE...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): freq = {} i, j = 0, 0 ans = -1 longest = "" while j < len(s): freq[s[j]] = 1 + freq.get(s[j], 0) while len(freq) > k: freq[s[i]] -= 1 if freq[s[i]] == 0: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP BIN_OP...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): pt1, pt2, ct, max_len = 0, 0, 0, 0 hash_map = {} while pt2 < len(s): if s[pt2] in hash_map: hash_map[s[pt2]] += 1 else: hash_map[s[pt2]] = 1 ct += 1 while ct >...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VA...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): d = {} ans = -1 p1, p2, n = 0, 0, len(s) b = False while p2 < n: if s[p2] in d: d[s[p2]] += 1 else: d[s[p2]] = 1 while len(d) > k and p1 <= p2: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): if len(s) < k: return -1 l = 0 D = {s[l]: 1} ans = -1 for r in range(1, len(s)): D[s[r]] = 1 + D.get(s[r], 0) if len(D) > k: while len(D) > k and l <= r: D...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): n = len(s) a = s i = 0 f = {} l, o = 0, 0 i = 0 j = 0 ans = -1 while i < n and j < n: if a[j] not in f or f[a[j]] == 0: f[a[j]] = 1 o += 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): if len(s) < k or len(set(s)) < k: return -1 map1 = {} start = 0 maxlength, curr = 0, -1 for end in range(len(s)): if s[end] not in map1: map1[s[end]] = 0 map1[s[end]] += 1 ...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR N...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): n = len(s) if len(set(s)) < k: return -1 count = [0] * 26 distinct = 0 ans = 0 i = j = 0 while j < n: if count[ord(s[j]) - ord("a")] == 0: distinct += 1 count[...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR FU...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): i = 0 j = 0 d = {} res = -1 n = len(s) while i < n: if s[i] not in d: if len(d) == k: while len(d) == k: d[s[j]] -= 1 if d[...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR VAR VAR IF FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER N...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): count = 0 l = 0 r = 0 arr = {} temp = -1 maxx = 0 while r < len(s): if s[r] not in arr: count += 1 arr[s[r]] = 1 elif r != temp1: arr[s[r]]...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR BIN_...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): dic = {} maxi = -(10**9) c = 0 start = 0 mini = -(10**9) for i in range(len(s)): if s[i] in dic: dic[s[i]] += 1 else: dic[s[i]] = 1 c += 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VA...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): d = {} i = 0 j = 0 maxl = 0 while j < len(s): if s[j] in d: d[s[j]] = d[s[j]] + 1 else: d[s[j]] = 1 if len(d) < k: j = j + 1 elif l...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR AS...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): ans = -1 ws = 0 d = {} for i in range(len(s)): c = s[i] if c in d: d[c] += 1 else: d[c] = 1 while len(d) > k: a = s[ws] d[a...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CA...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): mp = dict() i, j, ans = 0, 0, -1 n = len(s) while j < n: if s[j] in mp: mp[s[j]] += 1 else: mp[s[j]] = 1 if len(mp) < k: j += 1 if len(mp) ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF ...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): l = 0 count = {} maxLen = float("-inf") for r in range(len(s)): if s[r] not in count: count[s[r]] = 0 count[s[r]] += 1 while len(count) > k: count[s[l]] -= 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CA...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): ump = {} ump1 = {} start = 0 maxi = -1 if len(s) < k: return maxi for i in range(len(s)): ump1[s[i]] = ump1.get(s[i], 0) + 1 if len(ump1) < k: return maxi for end in r...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): characterSet = {} start = 0 result = "" i = 0 while i < len(s): if characterSet.get(s[i]) is not None: characterSet[s[i]] += 1 elif len(characterSet) == k: if i - start > ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NONE VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NU...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): i = 0 n = len(s) j = 0 res = "" maxres = 0 d = {} while j < n: res += s[j] if s[j] in d: d[s[j]] += 1 else: d[s[j]] = 1 if len(d) >...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR DICT WHILE VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): map = {} start = 0 end = 0 maxlen = -1 while end < len(s): map[s[end]] = map.get(s[end], 0) + 1 if len(map) == k: maxlen = max(maxlen, end - start + 1) while len(map) > k: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ...
Given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1. Example 1: Input: S = "aabacbebebe", K = 3 Output: 7 Explanation: "cbebebe" is the longest substring with K distinct characters. Example 2: Input: S = "aaa...
class Solution: def longestKSubstr(self, s, k): i = 0 j = 0 n = len(s) unique = {} longest = 0 while j < n: unique[s[j]] = unique.get(s[j], 0) + 1 if len(unique) == k: longest = max(longest, j - i + 1) elif len(uniq...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VA...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
for _ in range(int(input())): n, r = map(int, input().split(" ")) s = input() res = "" prev_s, last_res = s[:r], s[r:] p1, p2 = 0, r - 1 while p1 <= p2: res += prev_s[p1] if p1 != p2: res += prev_s[p2] p1 += 1 p2 -= 1 print(res[::-1] + last_res)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BI...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
n = int(input()) for i in range(n): a, b = map(int, input().split()) s = input() lst = s[b:] s = s[:b] r = "" for i in range(len(s) // 2): r += s[i] r += s[-(i + 1)] if len(s) % 2: r += s[len(s) // 2] r = r[::-1] print(r + lst)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR V...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
import sys def reverse(answer, i): for j in range(i // 2): answer[j], answer[i - j - 1] = answer[i - j - 1], answer[j] def findOriginalString(N, K, string): answer = [] answer.append(string[K // 2]) if K % 2: x = 2 flag = -1 j = K // 2 + 1 while j >= 0 and j <...
IMPORT FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
for _ in range(int(input())): n, k = map(int, input().split()) s = input() t = "" i = 0 p = k - 1 while i < p: t = s[i] + t t = s[p] + t i += 1 p -= 1 if k % 2 != 0: t = s[i] + t print(t + s[k:])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
for _ in range(int(input())): n, k = map(int, input().split()) arr = list(str(input()))[:n] narr = [] i = 0 j = k - 1 while i < j: narr.append(arr[i]) narr.append(arr[j]) i += 1 j -= 1 if i == j: narr.append(arr[i]) farr = narr[::-1] + arr[k:n] ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF ...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
t = int(input()) for _ in range(t): n, k = map(int, input().split()) s = list(input()) indlist = [] if k % 2 == 0: count = k x = 0 for i in range(k): indlist.append(count) if count - 2 == 0: x = 1 count = -1 if x...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIG...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
t = int(input()) while t: n, k = map(int, input().split()) s = input() s1 = "" if k % 2 != 0: s1 += s[k // 2] i = k // 2 + 1 j = k // 2 - 1 else: i = k // 2 j = k // 2 - 1 while j >= 0 and i < k: s1 += s[i] s1 += s[j] i += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING IF BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER AS...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
t = int(input()) while t > 0: t -= 1 n, k = [int(k) for k in input().split(" ")] s = str(input()) rev = s[:k] orig = s[k:] ans = [] while len(rev) > 0: if len(rev) > 0: ans.append(rev[0]) rev = rev[1:] if len(rev) > 0: ans.append(rev[-1]) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASS...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
ans = [] testcase = int(input()) for i in range(0, testcase): string = "" li = [] flag = 0 lenght, key = map(int, input().split()) ss = list(input()) for i in range(lenght): li.append([ss[i], i + 1]) for i in range(lenght): if key == 0: key = 1 flag = ...
ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL 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 LIST VAR VAR BIN_OP VAR NUMBER FOR VAR ...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
n = int(input()) for i in range(n): length, moves = [int(x) for x in str(input()).split(" ")] word = str(input()) a = "" b = word[moves:] c = word[:moves] is_odd = moves % 2 != 0 for j in range(moves // 2): a = c[j] + a a = c[moves - 1 - j] + a if is_odd: a = c[mo...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER AS...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
t = int(input()) for i in range(t): n, k = map(int, input().split()) str = input() ans = "" s = 0 e = k - 1 while s < e: ans += str[s] ans += str[e] s += 1 e -= 1 if s == e: ans += str[s] print(ans[::-1] + str[k:])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
def check(n, k, s): sharma = s[0:k] data = s[k:] ans = "" for i in range(0, k // 2): ans = sharma[-(i + 1)] + sharma[i] + ans if k % 2 != 0: ans = sharma[k // 2 : k // 2 + 1] + ans return ans + data t = int(input()) for _ in range(t): n, k = map(int, input().split()) s ...
FUNC_DEF ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
for _ in range(int(input())): n, k = map(int, input().split()) s = input() d = k l = k x = "" x += s[d // 2] if l % 2 == 1: i = 1 while i <= d // 2: x += s[d // 2 + i] x += s[d // 2 - i] i += 1 print(x + s[d:]) else: i =...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR STRING VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
t = int(input()) for i in range(t): n, k = map(int, input().split()) s = input() ans = "" even = 0 odd = 0 for j in range(k): if j % 2 == 0: ans += s[j - even] even += 1 else: ans += s[k - j + odd] odd += 1 ans_1 = ans[::-1] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR V...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
def rev(x): return x[::-1] def func(): n, k = map(int, input().split()) s = input() l = 0 r = k - 1 ans = "" while l <= r: ans += s[l] l += 1 if l <= r: ans += s[r] r -= 1 ans = rev(ans) for i in range(k, n): ans += s[i] p...
FUNC_DEF RETURN VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
for _ in range(int(input())): n, k = list(map(int, input().split())) str1 = input() str2 = str1[k:] emp = "" i = 0 j = k - 1 while i < j: emp += str1[i] emp += str1[j] i += 1 j -= 1 if i == j: emp += str1[j] k1 = emp[::-1] print(k1 + str2)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR ASSIGN ...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
for _ in range(int(input())): n, k = map(int, input().split()) s = input() ans = list(s) ans[k - 1 :: -2] = s[0 : (k + 1) // 2] ans[k % 2 : k : 2] = s[(k + 1) // 2 : k] print("".join(ans))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
for _ in range(int(input())): n, k = map(int, input().split()) srt = input() kstr = srt[:k] lst_str = srt[k:] oprn_lst = [" "] * (n + 1) odd = False if k % 2 == 1: odd = True nm = k // 2 k -= 1 cnt = 0 fin_ind = 0 for i in range(nm): oprn_lst[n - cnt] = ks...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST STRING BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBE...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
try: t = int(input()) while t: n, k = map(int, input().split()) s = input() org = "" i, j = 0, k - 1 while i < j: org += s[i] org += s[j] i += 1 j -= 1 if i == j: org += s[i] org = org[::-1] + s[k...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FU...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
import sys for _ in range(int(input())): n, k = map(int, input().split()) s = str(input()) a = "" p = int(k / 2) for i in range(k): if i % 2 == 0: if k % 2 == 0: p += i else: p -= i elif k % 2 == 0: p -= i e...
IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR IF BIN_O...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
def solve(s, k): res = ["-"] * len(s) res[-len(s) + k :] = s[-len(s) + k :] is_left = True i = -len(s) + k - 1 left, right = 0, k - 1 while left <= right: if is_left: res[i] = s[left] left += 1 else: res[i] = s[right] right -= 1 ...
FUNC_DEF ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR IF VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
t = int(input()) for i in range(t): n, k = map(int, input().split()) l = [0] * n s = input() c = 0 if k % 2 == 0: for j in range(k - 1, 0, -2): l[j] = s[c] c += 1 for x in range(n): if l[x] == 0: l[x] = s[c] c += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER FOR V...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
for t in range(int(input())): n, k = [int(i) for i in input().split()] s = input() original_right = s[k:] tl = s[:k] sl = "" l = 0 r = k - 1 steps = k while l != r > 0: sl += tl[l] if l < r: l += 1 else: l -= 1 l, r = r, l s...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR NUMBER VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
for _ in range(int(input())): n, r = map(int, input().split()) s = list(input()) ans = "" s1 = r // 2 s2 = r // 2 - 1 if r % 2 == 1: print(s[s1], end="") s1 += 1 for i in range(r // 2): print(s[s1], end="") print(s[s2], end="") s2 -= 1 s1 += 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER FOR VAR FUN...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
for _ in range(int(input())): n, k = map(int, input().split()) s1 = input() s = list(s1) x = 0 for i in range(k - 1, -1, -2): s[i] = s1[x] x += 1 for j in range((i + 1) % 2, k - 1, 2): s[j] = s1[x] x += 1 print("".join(s))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
def inpNum(): return int(input()) def inpNums(): return tuple(list(map(int, input().split()))) def inpList(): return list(map(int, input().split())) def solve(t: int): N, K = inpNums() s = input() ans = "" dir = 1 if K % 2 == 0 else -1 step = 0 i = int(K / 2) while K: ...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR NUMBER NUMB...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
t = int(input()) while t > 0: n, k = map(int, input().split()) S = input() p1 = S[:k] p2 = S[k:n] p11 = p1[: k // 2] p11 = p11[::-1] p12 = p1[k // 2 :] ans = "" if k % 2 == 0: for i in range(k // 2): ans = ans + p12[i] + p11[i] else: ans = ans + p12[0]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR STRING IF BIN_OP VAR NUMBER NUMBER FOR VA...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
for t in range(int(input())): n, k = map(int, input().split()) s = input() mid = k // 2 if k % 2 == 1: ans, i, j = s[mid], mid - 1, mid + 1 while i >= 0: ans += s[j] ans += s[i] i -= 1 j += 1 else: ans, j, i = "", mid, mid - 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIG...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
for _ in range(int(input())): n, k = map(int, input().split()) s = input() i = 0 j = k - 1 res = "" while i < j: res += s[i] res += s[j] i += 1 j -= 1 if i == j: res = res + s[i] m = res[::-1] o = s[k:] print(m + o)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER ...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
for _ in range(int(input())): n, d = map(int, input().split()) st = input() par = +1 if d % 2 == 1: par = -1 s = "" j = d // 2 for i in range(d): j += par * i s += st[j] par = -par try: print(s + st[d:]) except: print(s)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR EXPR ...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
for _ in range(int(input())): n, k = map(int, input().split()) inp = input() pref = "" i = 0 l = 0 while l <= k: if i != k - i - 1: pref += f"{inp[i]}{inp[k - i - 1]}" l += 2 i += 1 else: pref += inp[i] break if ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR IF VA...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
ans = "" for _ in range(int(input())): n, k = list(map(int, input().split())) s = input() sub1 = "" sub2 = s[k:] l, r = 0, k - 1 while l <= r: sub1 += s[l] if l != r: sub1 += s[r] r -= 1 l += 1 ans += sub1[::-1] + sub2 + "\n" print(ans)
ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR BIN_...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
t = int(input()) for i in range(t): n, m = map(int, input().split()) l = input() le = [] ri = [] r = [None] * m if m % 2 == 0: ri = l[m // 2 : m] le = l[m // 2 - 1 :: -1] r[::2] = ri r[1::2] = le r[m:] = l[m:] else: ri = l[m // 2 + 1 : m] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NONE VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMB...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
T = int(input()) for _ in range(T): N, K = map(int, input().split()) S = input() res = "" i = 0 j = K - 1 while i < j: res = res + S[i] res = res + S[j] i = i + 1 j = j - 1 if i == j: res = res + S[i] res = res[::-1] tmp = res + S[K:N] prin...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIG...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
for _ in range(int(input())): n, k = list(map(int, input().split())) s = input() p1 = k // 2 p2 = p1 + 1 flag = True if k % 2 == 0: flag = False p1 -= 1 p2 -= 1 tmp = k while tmp > 0: if flag: print(s[p1], end="") p1 -= 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBE...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
test_cases = int(input()) for _ in range(test_cases): N, K = map(int, input().split()) S = input().rstrip("\n") S1 = list(S) Current_Character = 0 for i in range(K, 0, -2): S1[i - 1] = S[Current_Character] Current_Character += 1 Next = 1 + K % 2 for i in range(Next, K, 2): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUM...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
x = int(input()) for i in range(x): n, k = input().split() n = int(n) k = int(k) a = input() if k & 1 == 0: z = k // 2 b = 1 while z < k: print(a[z] + a[z - b], end="") b += 2 z += 1 for ll in range(k, n): print(a[ll], e...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
def soln(n, k, s): beg = 0 end = k - 1 res = [""] * n for i in range(k): if not i & 1: res[i] = s[beg] beg += 1 else: res[i] = s[end] end -= 1 res[:k] = res[k - 1 :: -1] for i in range(k, n): res[i] = s[i] return "".join...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN FUNC_CALL S...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
for _ in range(int(input())): m, n = map(int, input().split()) s = input() mainarr = list(s) arr = [] arr[:] = mainarr[:n] newarr = [] l, r = 0, n - 1 for i in range(0, n): if i % 2 == 0: newarr.append(arr[l]) l += 1 else: newarr.append...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER EXPR FU...
Alice initially has a string S of length N, and she decides to modify it! Her modification consists of K steps numbered from 1 to K. In the i-th step, Alice reverses the prefix of length i of S. For example, suppose Alice starts with S = \texttt{abferty}, and she modifies it via 3 steps, then: After the first step, \t...
t = int(input()) while t: n, k = map(int, input().split()) s = input() a = s[0:k] b = s[k:] c = [] var1 = 0 var2 = k - 1 for i in range(k): if i % 2 == 0: c.append(a[var1]) var1 = var1 + 1 else: c.append(a[var2]) var2 = var2...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ...
Given a string that consists of only uppercase English letters, you can replace any letter in the string with another letter at most k times. Find the length of a longest substring containing all repeating letters you can get after performing the above operations. Note: Both the string's length and k will not exceed 1...
class Solution: def characterReplacement(self, s, k): start = end = maxn = 0 alpha_dict = collections.defaultdict(int) for end in range(1, len(s) + 1): alpha_dict[s[end - 1]] += 1 maxn = max(maxn, alpha_dict[s[end - 1]]) if end - start > k + maxn: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN BIN_OP VAR VAR
Given a string that consists of only uppercase English letters, you can replace any letter in the string with another letter at most k times. Find the length of a longest substring containing all repeating letters you can get after performing the above operations. Note: Both the string's length and k will not exceed 1...
class Solution: def characterReplacement(self, s, k): if s == "": return 0 count = {} lo = 0 hi = 0 max_letter = 0 for hi in range(len(s)): try: count[s[hi]] += 1 except: count[s[hi]] = 1 ...
CLASS_DEF FUNC_DEF IF VAR STRING RETURN NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER...
Given a string that consists of only uppercase English letters, you can replace any letter in the string with another letter at most k times. Find the length of a longest substring containing all repeating letters you can get after performing the above operations. Note: Both the string's length and k will not exceed 1...
class Solution: def characterReplacement(self, s, k): ls = len(s) start, end, max_len = 0, 0, 0 char_map, cnt, cur_max_char = {}, 0, 0 while end < ls: if s[end] in char_map: char_map[s[end]] += 1 else: char_map[s[end]] = 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR DICT NUMBER NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSI...
Given a String S consisting only lowercase alphabets and an integer K. Find the count of all substrings of length K which have exactly K-1 distinct characters. Example 1: Input: S = "abcc" K = 2 Output: 1 Explanation: Possible substrings of length K = 2 are ab : 2 distinct characters bc : 2 distinct characters cc : ...
class Solution: def countOfSubstrings(self, S, K): char_freq = [0] * 26 l, res, distinct = 0, 0, 0 for i in range(len(S)): indx = ord(S[i]) - ord("a") char_freq[indx] += 1 if char_freq[indx] == 1: distinct += 1 if i >= K: ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER IF VAR ...
Given a String S consisting only lowercase alphabets and an integer K. Find the count of all substrings of length K which have exactly K-1 distinct characters. Example 1: Input: S = "abcc" K = 2 Output: 1 Explanation: Possible substrings of length K = 2 are ab : 2 distinct characters bc : 2 distinct characters cc : ...
class Solution: def countOfSubstrings(self, s, k): count = 0 mp = {} for i in range(k): if s[i] not in mp: mp[s[i]] = 1 else: mp[s[i]] += 1 if len(mp) == k - 1: count += 1 j = 0 n = len(s) fo...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR V...
Given a String S consisting only lowercase alphabets and an integer K. Find the count of all substrings of length K which have exactly K-1 distinct characters. Example 1: Input: S = "abcc" K = 2 Output: 1 Explanation: Possible substrings of length K = 2 are ab : 2 distinct characters bc : 2 distinct characters cc : ...
class Solution: def countOfSubstrings(self, s, k): arr = [(0) for i in range(26)] i = 0 j = 0 n = len(s) c = 0 count = 0 while j < n: arr[ord(s[j]) - 97] += 1 if arr[ord(s[j]) - 97] == 1: c += 1 if j - i + 1...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR...
Given a String S consisting only lowercase alphabets and an integer K. Find the count of all substrings of length K which have exactly K-1 distinct characters. Example 1: Input: S = "abcc" K = 2 Output: 1 Explanation: Possible substrings of length K = 2 are ab : 2 distinct characters bc : 2 distinct characters cc : ...
class Solution: def countOfSubstrings(self, s, k): i, j = 0, 0 def check(d, k): count = 0 fl = 0 for i in d: if d[i] != 0: if d[i] > 2: return False elif d[i] == 2: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER IF VAR VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT WHILE VAR FUNC_CA...
Given a String S consisting only lowercase alphabets and an integer K. Find the count of all substrings of length K which have exactly K-1 distinct characters. Example 1: Input: S = "abcc" K = 2 Output: 1 Explanation: Possible substrings of length K = 2 are ab : 2 distinct characters bc : 2 distinct characters cc : ...
class Solution: def countOfSubstrings(self, S, K): if len(S) < K: return 0 d = {} uniq = 0 ans = 0 for i in range(K): if S[i] in d: d[S[i]] += 1 else: uniq += 1 d[S[i]] = 1 if uniq ==...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF V...
Given a String S consisting only lowercase alphabets and an integer K. Find the count of all substrings of length K which have exactly K-1 distinct characters. Example 1: Input: S = "abcc" K = 2 Output: 1 Explanation: Possible substrings of length K = 2 are ab : 2 distinct characters bc : 2 distinct characters cc : ...
class Solution: def countOfSubstrings(self, S, k): l = 0 ans = 0 map = [0] * 26 for i in range(k): if map[ord(S[i]) - ord("a")] == 0: map[ord(S[i]) - ord("a")] = 1 l += 1 else: map[ord(S[i]) - ord("a")] += 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBE...
Given a String S consisting only lowercase alphabets and an integer K. Find the count of all substrings of length K which have exactly K-1 distinct characters. Example 1: Input: S = "abcc" K = 2 Output: 1 Explanation: Possible substrings of length K = 2 are ab : 2 distinct characters bc : 2 distinct characters cc : ...
class Solution: def countOfSubstrings(self, S, K): res = list() l = 0 n = len(S) count = 0 map = dict() for r in range(n): map[S[r]] = map.get(S[r], 0) + 1 if r - l + 1 == K: if len(map) == K - 1: count += 1...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF FUNC_CALL...
Given a String S consisting only lowercase alphabets and an integer K. Find the count of all substrings of length K which have exactly K-1 distinct characters. Example 1: Input: S = "abcc" K = 2 Output: 1 Explanation: Possible substrings of length K = 2 are ab : 2 distinct characters bc : 2 distinct characters cc : ...
class Solution: def countOfSubstrings(self, S, K): if K > 27: return 0 result = 0 for i in range(len(S) - K + 1): A = S[i : i + K] if len(set(A)) == K - 1: result += 1 return result
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR
Given a String S consisting only lowercase alphabets and an integer K. Find the count of all substrings of length K which have exactly K-1 distinct characters. Example 1: Input: S = "abcc" K = 2 Output: 1 Explanation: Possible substrings of length K = 2 are ab : 2 distinct characters bc : 2 distinct characters cc : ...
class Solution: def countOfSubstrings(self, s, k): ans = {} res = 0 for i in range(k): ans[s[i]] = ans.get(s[i], 0) + 1 if len(ans) == k - 1: res += 1 for i in range(k, len(s)): ans[s[i - k]] -= 1 if ans[s[i - k]] == 0: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR...
Given a String S consisting only lowercase alphabets and an integer K. Find the count of all substrings of length K which have exactly K-1 distinct characters. Example 1: Input: S = "abcc" K = 2 Output: 1 Explanation: Possible substrings of length K = 2 are ab : 2 distinct characters bc : 2 distinct characters cc : ...
class Solution: def countOfSubstrings(self, S, K): res = 0 i, j = 0, 0 map = {} while i < len(S): map[S[i]] = 1 + map.get(S[i], 0) if i + 1 >= K: if len(map) == K - 1: res = res + 1 map[S[j]] -= 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR DICT WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR AS...
Given a String S consisting only lowercase alphabets and an integer K. Find the count of all substrings of length K which have exactly K-1 distinct characters. Example 1: Input: S = "abcc" K = 2 Output: 1 Explanation: Possible substrings of length K = 2 are ab : 2 distinct characters bc : 2 distinct characters cc : ...
class Solution: def countOfSubstrings(self, S, K): d = dict() dist = 0 for i in range(K): j = S[i] if j in d.keys(): d[j] = d.get(j) + 1 else: dist += 1 d[j] = 1 tot = 0 if dist == K - 1: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR ASSIGN VAR VAR VAR IF VA...
Given a String S consisting only lowercase alphabets and an integer K. Find the count of all substrings of length K which have exactly K-1 distinct characters. Example 1: Input: S = "abcc" K = 2 Output: 1 Explanation: Possible substrings of length K = 2 are ab : 2 distinct characters bc : 2 distinct characters cc : ...
class Solution: def countOfSubstrings(self, S, K): x = 0 s = {} for i in range(K): if s.get(S[i]): s[S[i]] += 1 else: s[S[i]] = 1 i, j = 0, K while j <= len(S): if len(s) == K - 1: x += 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR WHILE VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR V...
Given a String S consisting only lowercase alphabets and an integer K. Find the count of all substrings of length K which have exactly K-1 distinct characters. Example 1: Input: S = "abcc" K = 2 Output: 1 Explanation: Possible substrings of length K = 2 are ab : 2 distinct characters bc : 2 distinct characters cc : ...
class Solution: def countOfSubstrings(self, s, k): i = 0 j = 0 c = 0 dic = {} while j < len(s): if s[j] not in dic: dic[s[j]] = 1 else: dic[s[j]] += 1 if j - i + 1 == k: if len(dic) == k - 1:...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL V...
Given a String S consisting only lowercase alphabets and an integer K. Find the count of all substrings of length K which have exactly K-1 distinct characters. Example 1: Input: S = "abcc" K = 2 Output: 1 Explanation: Possible substrings of length K = 2 are ab : 2 distinct characters bc : 2 distinct characters cc : ...
class Solution: def countOfSubstrings(self, S, K): hm = {} final_answer = 0 for i in range(K): if S[i] in hm: hm[S[i]] += 1 else: hm[S[i]] = 1 if len(hm) == K - 1: final_answer += 1 i = 0 j = K ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR IF VAR VAR VAR VA...
Given a String S consisting only lowercase alphabets and an integer K. Find the count of all substrings of length K which have exactly K-1 distinct characters. Example 1: Input: S = "abcc" K = 2 Output: 1 Explanation: Possible substrings of length K = 2 are ab : 2 distinct characters bc : 2 distinct characters cc : ...
class Solution: def countOfSubstrings(self, S, K): fr = [0] * 26 d = 0 c = 0 for i in range(K): fr[ord(S[i]) - 97] += 1 if fr[ord(S[i]) - 97] == 1: d += 1 if d == K - 1: c += 1 le = 0 ri = K while ri...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR V...