description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
t = int(input()) for i in range(0, t): str = input() temp = 0 maximum = 0 j = 0 test = 0 if str[0] == ">" or str[0] == "<": test = 1 for i in range(0, len(str)): if str[i] == "=": continue elif str[i] == str[j] and i != 0: temp += 1 j = i else: maximum = max(maximum, temp) temp = 0 j = i maximum = max(maximum, temp) if j != 0 or test == 1: print(maximum + 2) else: print(1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
for t in range(int(input())): s = input() l = 0 g = 0 e = 0 maxl = 0 maxg = 0 i = 0 j = 0 length = len(s) for x in range(length): if s[x] == "=": e += 1 elif s[x] == "<": l += 1 i += 1 j = 0 if maxl < i: maxl = i else: g += 1 j += 1 i = 0 if maxg < j: maxg = j if maxl < i: maxl = i if maxg < j: maxg = j if e == length: print(1) elif l == length or g == length: print(length + 1) elif maxl > maxg: print(1 + maxl) else: print(1 + maxg)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
t = int(input()) for z in range(t): p, q = 1, 0 s = [] a = input() for i in a: if i != "=": s.append(i) n = len(s) if n == 1: print(2) continue for i in range(n - 1): if s[i] == s[i + 1]: p += 1 else: p = 1 q = max(p, q) print(q + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
for t in range(int(input())): s = input().replace("=", "") a = s.split(">") + s.split("<") a = list(filter(lambda x: x != "", a)) l = 0 for i in a: l = max(l, len(i)) print(l + 1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN VAR BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
tc = int(input()) while tc: str = input() l = len(str) tl = l pre = str[0] cnt = 1 max = 0 flag = 0 for x in range(1, l): if str[x] != "=": flag = 1 cur = str[x] if cur == pre: cnt += 1 else: if max < cnt: max = cnt cnt = 1 pre = cur if flag == 0 and pre == "=": print("1") else: if max < cnt: max = cnt if max + 1 > 2: print(max + 1) else: print("2") tc = tc - 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
for _ in range(int(input())): line = input() line = line.replace("=", "") values = list(line) result = 0 answer = 0 if len(values) == 0: print(1) else: for i in range(1, len(values)): if values[i] == values[i - 1]: answer = answer + 1 else: if result < answer: result = answer answer = 0 if result < answer: result = answer print(result + 2)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
test = int(input()) while test != 0: abc = input() abc = abc.replace("=", "") maxi = 0 count = 0 count1 = 0 for i in abc: if i == abc[0]: count = count + 1 count1 = 0 else: count1 = count1 + 1 count = 0 maxi = max(count, count1, maxi) print(maxi + 1) test = test - 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
for x in range(int(input())): s = input() maxx = 0 a, b = 0, 0 for i in range(len(s)): if s[i] == "<": a += 1 b = 0 if a > maxx: maxx = a elif s[i] == ">": b += 1 a = 0 if b > maxx: maxx = b print(maxx + 1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
for i in range(int(input())): str1 = input() leftbrack, rightbrack, count = 0, 0, 0 for _ in range(0, len(str1)): if str1[_] == "<": leftbrack, rightbrack = leftbrack + 1, 0 if leftbrack > count: count = leftbrack elif str1[_] == ">": rightbrack, leftbrack = rightbrack + 1, 0 if rightbrack > count: count = rightbrack print(count + 1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
for _ in range(int(input())): s = input() ans = 0 last = "?" curr = 0 for ch in s: if ch == "=": continue if ch != last: ans = max(ans, curr) curr = 1 last = ch else: curr += 1 ans = max(ans, curr) print(ans + 1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
t = int(input()) for i in range(t): a = input() temp = 0 ans = 0 b = a.replace("=", "") for j in range(len(b)): if b[j] == "<": temp += 1 else: temp = 0 ans = max(ans, temp) temp = 0 for j in range(len(b)): if b[j] == ">": temp += 1 else: temp = 0 ans = max(ans, temp) print(ans + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
casos = int(input()) while casos > 0: signos = input() maximo = 1 largo = len(signos) i = 0 while i < largo: if signos[i] != "=": necesito = 0 j = i while j < largo: if signos[i] != signos[j] and signos[j] != "=": break elif signos[i] == signos[j]: necesito += 1 j += 1 necesito += 1 maximo = int((maximo + necesito + abs(maximo - necesito)) / 2) i += j - i else: i += 1 print(maximo) casos -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR STRING IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
t = int(input()) for i in range(t): line = input() line = line.replace("=", "") max_seq = 1 curr_seq = 1 try: pre = line[0] except: print(1) continue for curr in line[1:]: if curr == pre: curr_seq += 1 else: max_seq = max(max_seq, curr_seq) curr_seq = 1 pre = curr max_seq = max(max_seq, curr_seq) print(max_seq + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
t = int(input().strip()) for _ in range(t): numList = [] less, great, maxVal = 0, 0, 0 sign = list(input().strip()) for iter in sign: if iter == "<": great = 0 less = less + 1 if less > maxVal: maxVal = less elif iter == ">": less = 0 great = great + 1 if great > maxVal: maxVal = great print(maxVal + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
def main(): t = eval(input()) while t != 0: str = input() Cur1 = 0 Cur2 = 0 Max = 0 for i in str: if i == "<": Cur1 = Cur1 + 1 if Cur2 != 0: Cur2 = 0 elif i == ">": Cur2 = Cur2 + 1 if Cur1 != 0: Cur1 = 0 Max = max(max(Cur1, Cur2) + 1, Max) print(Max) t = t - 1 main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
t = input() l = [] j = 0 lenm = lenb = 0 mas = [] dlina = 0 for i in range(int(t)): stroka = input() n = len(stroka) while j < n and stroka[j] == "=": j = j + 1 if j != n: curr = stroka[j] for c in stroka[j:]: if c == curr: mas.append(c) if len(mas) > dlina: dlina = len(mas) elif c != "=": curr = c mas = [c] if n > 0: l.append(dlina + 1) else: l.append(0) mas = [] dlina = 0 j = 0 for x in l: print(x)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR ASSIGN VAR LIST VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
for x in range(0, int(input())): s = input() s = s.replace("=", "") res, b, l, count = 0, 0, len(s), 0 if l > 0: while b < l: curr = s[b] b += 1 count = 1 while b < l and s[b] == curr: count += 1 b += 1 res = max(res, count) print(res + 1)
FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
for _ in range(int(input())): l = list(input()) temp = ["<", "="] fg, c = 0, 0 ans1, ans2 = 0, 0 for i in range(len(l)): if l[i] in temp: fg = 1 if l[i] == "<": c += 1 elif fg == 1: ans1 = max(ans1, c) fg = 0 c = 0 if fg == 1: ans1 = max(ans1, c) ans1 += 1 temp = [">", "="] fg, c = 0, 0 for i in range(len(l)): if l[i] in temp: fg = 1 if l[i] == ">": c += 1 elif fg == 1: ans2 = max(ans2, c) fg = 0 c = 0 if fg == 1: ans2 = max(ans2, c) ans2 += 1 print(max(ans1, ans2))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR LIST STRING STRING ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
t = int(input()) for i in range(t): s = input() m = 0 c = 0 j = 0 while j < len(s): if s[j : j + 1] == "=": j = j + 1 continue c = 0 if s[j : j + 1] == "<": while s[j : j + 1] != ">" and j < len(s): if s[j : j + 1] == "=": j = j + 1 continue c = c + 1 j = j + 1 if c > m: m = c c = 0 if s[j : j + 1] == ">": while s[j : j + 1] != "<" and j < len(s): if s[j : j + 1] == "=": j = j + 1 continue c = c + 1 j = j + 1 if c > m: m = c print(m + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING WHILE VAR VAR BIN_OP VAR NUMBER STRING VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING WHILE VAR VAR BIN_OP VAR NUMBER STRING VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
def solution(): s = input() last_char = "-" P = 0 temp = 0 for i in range(0, len(s)): if s[i] == "=": continue if last_char == s[i]: temp = temp + 1 else: P = max(temp, P) temp = 1 last_char = s[i] P = max(temp, P) print(P + 1) T = int(input()) while T > 0: T = T - 1 solution()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
o = int(input()) for h in range(0, o): s1 = input() if s1.count("=") == len(s1): print(1) else: s = "" for j in s1: if j != "=": s = s + j s = s + "a" max = 1 while len(s) != 1: i = s.find("<") j = s.find(">") if i == -1: i = len(s) - 1 if j == -1: j = len(s) - 1 if j > i: a = len(s[i:j]) s = s[j:] else: a = len(s[j:i]) s = s[i:] if a > max: max = a print(max + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
for _ in range(int(input())): s = input() l = len(s) s1, s2 = [0] * l, [0] * l if s[0] == ">": s1[0] = 1 elif s[0] == "<": s2[0] = 1 for i in range(1, l): if s[i] == ">": if s[i - 1] == ">" or s[i - 1] == "=": s1[i] = s1[i - 1] + 1 elif s[i - 1] == "<": s1[i] = 1 elif s[i] == "<": if s[i - 1] == "<" or s[i - 1] == "=": s2[i] = s2[i - 1] + 1 elif s[i - 1] == ">": s2[i] = 1 else: s1[i] = s1[i - 1] s2[i] = s2[i - 1] print(max(max(s1), max(s2)) + 1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER STRING ASSIGN VAR NUMBER NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
def count(_str): min = 1 max = 1 val = 1 for i in range(len(_str)): if _str[i] == "<": val += 1 elif _str[i] == ">": val -= 1 if val > max: max = val elif val < min: min = val print("min={0} max={1}".format(min, max)) return max - min + 1 class CountMaxSegment: def __init__(self): self.maxCount = 0 def calcMax(self, newMax): if newMax > self.maxCount: self.maxCount = newMax def count(self, _str): countLT = 0 countGT = 0 for i in range(len(_str)): if _str[i] == "<": self.calcMax(countGT) countGT = 0 countLT += 1 elif _str[i] == ">": self.calcMax(countLT) countLT = 0 countGT += 1 self.calcMax(countGT) self.calcMax(countLT) if self.maxCount == 0: return 1 return self.maxCount + 1 def ni(): s = input() while len(s) == 0: s = input() try: return int(s) except: return 0 def ns(): s = input() while len(s) == 0: s = input() return s def solve(): T = ni() while T > 0: T -= 1 counter = CountMaxSegment() print(counter.count(ns())) def test(): print(count(">")) print(count("<")) print(count("=")) print(count("=<")) print(count(">=")) print(count(">>>>=<<<")) signs = ">><>>>" print(count(signs)) counter = CountMaxSegment() print(counter.count("=")) print(counter.count("<")) print(counter.count(signs)) solve()
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
T = int(input()) for _ in range(T): ipStr = input() maxValue = 0 currentCh = "<" currentValue = 0 for ch in ipStr: if ch == "=": continue elif ch == currentCh: currentValue += 1 else: currentValue = 1 currentCh = ch if currentValue > maxValue: maxValue = currentValue print(maxValue + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
T = int(input()) for i in range(T): x = input().replace("=", "") max_right = 0 max_left = 0 curr_right = 0 curr_left = 0 right = False left = False for j in x: if j == ">": curr_right += 1 if not right: right = True if left: left = False if max_left < curr_left: max_left = curr_left curr_left = 0 elif j == "<": curr_left += 1 if not left: left = True if right: right = False if max_right < curr_right: max_right = curr_right curr_right = 0 if curr_left > max_left: max_left = curr_left if curr_right > max_right: max_right = curr_right print(max(max_right, max_left) + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR STRING VAR NUMBER IF VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
from itertools import groupby test = int(input()) for i in range(test): signs = list(input()) Signs = [j for j in signs if j != "="] if Signs.count("=") == len(Signs): print("1") else: consecutiveList = [sum(1 for l in g) for k, g in groupby(Signs)] print(max(consecutiveList) + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR STRING IF FUNC_CALL VAR STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
t = int(input()) for i in range(t): s = input() count, temp, less, great, equals = 0, 0, 0, 0, 0 for j in range(0, len(s)): if s[j] == "<": less += 1 great = 0 if count <= less: count = less + 1 elif s[j] == ">": great += 1 less = 0 temp = 2 if count <= great: count = great + 1 if s[j] == "=": equals = 1 if equals != 0 and count == 0: print(equals) else: print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
import itertools for test in range(int(input())): a = input() c = 0 m = a.count("=") if m == len(a): c = 1 print("1") if c == 0: n = a.replace("=", "") l = list(n) z = [(x[0], len(list(x[1]))) for x in itertools.groupby(l)] print(max(z, key=lambda x: x[1])[1] + 1)
IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
for i in range(int(input())): st = input() a = "<" b = ">" c = "=" j = 0 count = 1 list2 = [x for x in st if x != "="] if len(list2) == 0: print(1) else: list1 = [] while j < len(list2) - 1: if list2[j] == list2[j + 1]: count += 1 else: list1.append(count) count = 1 j += 1 list1.append(count) max1 = list1[0] for k in list1: if k > max1: max1 = k print(max1 + 1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
for _ in range(int(input())): srng = str(input()) srng = srng.replace("=", "") c1 = 0 c2 = 0 mx = 0 for a in srng: if a == ">": c1 += 1 c2 = 0 if c1 > mx: mx = c1 elif a == "<": c2 += 1 c1 = 0 if c2 > mx: mx = c2 print(mx + 1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
t = int(input()) for _ in range(t): st = input() st = st.replace("=", "") if len(st) > 0: ans = 0 temp = 1 for i in range(1, len(st)): if st[i] == st[i - 1]: temp += 1 else: ans = max(ans, temp + 1) temp = 1 ans = max(ans, temp + 1) print(ans) else: print(1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
def solve(s): temp = [] for c in s: if c != "=": temp.append(c) count = 1 ans = 1 if temp: for i in range(1, len(temp)): if temp[i] == temp[i - 1]: count += 1 else: ans = max(ans, count) count = 1 ans = max(ans, count) print(ans + 1) else: print(1) n = int(input()) for i in range(n): s = input().strip() solve(s)
FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
for _ in range(int(input())): st = input().replace("=", "") if not len(st): print(1) else: cu = mx = 1 for j in range(1, len(st)): if st[j] == st[j - 1]: cu += 1 else: mx = max(mx, cu) cu = 1 print(max(mx + 1, cu + 1))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING STRING IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
t = int(input()) for a0 in range(t): n = input() gis = [] g1 = 0 l1 = 0 z = n.replace("=", "") for a1 in z: if a1 == ">": g1 += 1 else: gis.append(g1) g1 = 0 gis.append(g1) for a2 in z: if a2 == "<": l1 += 1 else: gis.append(l1) l1 = 0 gis.append(l1) print(max(gis) + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING FOR VAR VAR IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
def solve(sign): k = 0 minVal = k maxVal = k n = len(sign) for i in range(n): if sign[i] == ">": k = k - 1 if sign[i] == "<": k = k + 1 minVal = min(minVal, k) maxVal = max(maxVal, k) kVal = -1 * minVal + 1 p = kVal + maxVal return p pass def solve1(sign): k = 0 minVal = k maxVal = k sign = sign + "?" n = len(sign) curSign = sign[0] count = 1 for i in range(1, n): if sign[i] == curSign: count += 1 else: if sign[i] == "=": continue if curSign == "<" and count <= abs(minVal): k = maxVal elif curSign == "<" and count > abs(minVal): k = count - abs(minVal) maxVal = max(maxVal, k) elif curSign == ">" and count <= maxVal: k = minVal elif curSign == ">" and count > maxVal: k = maxVal - count minVal = min(minVal, k) curSign = sign[i] count = 1 kVal = -1 * minVal + 1 p = kVal + maxVal return p pass n = int(input()) for i in range(n): line = input() p = solve1(line) print(p) p = 10000000000000
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR STRING IF VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING VAR VAR ASSIGN VAR VAR IF VAR STRING VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
for i in range(int(input())): s = input() req = -1 con = 1 i = 1 prev = s[0] while i < len(s): if s[i] == "=": pass elif s[i] == prev: con += 1 else: if con > req: req = con con = 1 prev = s[i] i += 1 if con > req: req = con a = s.count("<") b = s.count(">") if a != 0 or b != 0: req += 1 print(req)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
for _ in range(int(input())): q = input() x = 0 o = 0 y = "=" + q z = -1 c = -1 for i in range(1, len(y)): if y[i] == ">" and (y[i - 1] == "=" or y[i - 1] == ">"): x += 1 elif y[i] == "<" and (y[i - 1] == "=" or y[i - 1] == "<"): o += 1 else: if z < o: z = o if c < x: c = x if y[i] == ">": x = 1 o = 0 if y[i] == "<": o = 1 x = 0 if z < o: z = o if c < x: c = x print(max(z, c) + 1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
t = int(input()) i = 0 while i < t: sum = 0 st = input() st = st.replace("=", "") l = len(st) j = 0 max = 0 if l == 0: print(1) else: while j < l - 1: if st[j] == st[j + 1]: sum += 1 else: sum = 0 if sum > max: max = sum j += 1 print(max + 2) i += 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
for t in range(int(input())): s = input() ans = count = 0 last = s[0] for c in s: if c == "=": continue if c == last: count += 1 else: ans = max(ans, count) count = 1 last = c print(max(ans, count) + 1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR STRING IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
for i in range(int(input())): s = input() z = [] l = g = 1 for j in s: if j == "<": g = g + 1 z.append(l) l = 1 elif j == ">": l = l + 1 z.append(g) g = 1 z.append(l) z.append(g) print(max(z))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
for _ in range(int(input())): s = input() p = "=" c = 1 ans = 1 for i in range(len(s)): if s[i] == "=": continue if s[i] == p: c += 1 else: c = 1 if c + 1 > ans: ans = c + 1 p = s[i] print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
test = int(input()) while test: st = input() mx = freq = 0 st += "0" l = len(st) p = "=" for i in range(0, l - 1): if st[i] == "=": continue elif (st[i] == "<" or st[i] == ">") and freq == 0: freq += 1 p = st[i] elif p == st[i]: freq += 1 else: if freq > mx: mx = freq freq = 1 p = st[i] if freq > mx: mx = freq print(mx + 1) test -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR STRING IF VAR VAR STRING VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
t = int(input()) for z in range(t): s = input() j = 1 ans = 1 a = [] for i in s: if i != "=": a.append(i) if len(a) == 0: print(1) continue for i in range(len(a) - 1): if a[i] == a[i + 1]: j += 1 ans = max(ans, j) else: j = 1 print(ans + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
t = int(input()) for i in range(t): s = input() l = len(s) flag = 0 cnt = 0 mx = 0 for j in range(l): if flag == 1: if s[j] == "<": cnt += 1 elif s[j] == ">": mx = max(mx, cnt) cnt = 1 flag = 2 elif flag == 2: if s[j] == ">": cnt += 1 elif s[j] == "<": mx = max(mx, cnt) cnt = 1 flag = 1 elif s[j] == "<": cnt = 1 flag = 1 elif s[j] == ">": cnt = 1 flag = 2 mx = max(mx, cnt) print(mx + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
n = int(input()) for i in range(0, n): text = input() m = len(text) maxnum1 = num1 = 1 for i in range(0, m): if text[i] == "<": num1 = num1 + 1 elif text[i] == ">": if num1 > maxnum1: maxnum1 = num1 num1 = 1 if num1 > maxnum1: maxnum1 = num1 maxnum2 = num2 = 1 for i in range(0, m): if text[i] == ">": num2 = num2 + 1 elif text[i] == "<": if num2 > maxnum2: maxnum2 = num2 num2 = 1 if num2 > maxnum2: maxnum2 = num2 maxnum = max(maxnum1, maxnum2) print(maxnum)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR STRING IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
t = int(input()) for I in range(t): s = input().rstrip("\r") count1 = 1 flag1 = 0 flag2 = 0 max1 = 1 for i in range(len(s)): if s[i] == "<": flag1 = 1 if flag2 == 1: count1 = 1 flag2 = 0 count1 += 1 if count1 > max1: max1 = count1 elif s[i] == ">": flag2 = 1 if flag1 == 1: count1 = 1 flag1 = 0 count1 += 1 if count1 > max1: max1 = count1 print(max1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
t = int(input()) for _ in range(t): seq = list(input()) counter = 0 maximum = 0 Greaterthan = False for i in seq: if i == "<": if Greaterthan: counter += 1 else: if counter > maximum: maximum = counter Greaterthan = True counter = 1 elif i == ">": if Greaterthan: if counter > maximum: maximum = counter Greaterthan = False counter = 1 else: counter += 1 if counter > maximum: maximum = counter print(maximum + 1)
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 VAR IF VAR STRING IF VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR STRING IF VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
N = int(input()) z = 0 while z < N: z += 1 st = input() i = 0 maxi = 0 s1 = s2 = 0 while i < len(st): if st[i] is "<": s1 += 1 s2 = 0 if st[i] is ">": s2 += 1 s1 = 0 if max(s1, s2) > maxi: maxi = max(s1, s2) i += 1 print(maxi + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
t = int(input()) while t > 0: s = input() s = s.replace("=", "") i, j, m = 0, 0, 0 while i < len(s): j = i while j < len(s) and s[j] == s[i]: j += 1 m = max(m, j - i) i = j print(m + 1) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
for _ in range(int(input())): s = list("".join(input().split("="))) n = 1 m = 0 i = 0 if s == []: m = 1 while i < len(s): if s[i] == "<": n += 1 if n > m: m = n elif s[i] == ">": if i + 1 < len(s) and s[i + 1] != ">": n = 1 elif i + 1 < len(s) and s[i + 1] == ">": for j in range(i, len(s)): if s[j] == "<": x = j - i i = j - 1 if n - x < 1: y = n + 1 + (n - x) * -1 if y > m: m = y break elif j == len(s) - 1: x = j - i i = j if n - x < 1: y = n + 2 + (n - x) * -1 if y > m: m = y n = 1 elif n == 1: n = 1 if m < 2: m = 2 else: n = n - 1 i += 1 print(m)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR STRING IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
for j in range(int(input())): count = 0 ns = "" str1 = "" str1 = input() count1 = 0 max1 = 0 max2 = 0 for i in range(len(str1)): if str1[i] == "=": continue ns += str1[i] for k in range(len(ns)): if ns[k] == "<": count1 = 0 count += 1 elif ns[k] == ">": count = 0 count1 += 1 if max1 < count: max1 = count elif max1 < count1: max1 = count1 print(max1 + 1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and the signs are correct. That is, if a sign '<' is preceded by the integer a and followed by an integer b, then a should be less than b. Likewise for the other two signs as well. Chef can take some positive integers in the range [1, P] and use a number in the range as many times as he wants. Help Chef find the minimum possible P with which he can create a valid sequence. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains the string of signs s, where each sign is either '<', '=' or a '>'. -----Output----- For each test case, output a single line containing an integer corresponding to the minimum possible P. -----Constraints----- - 1 ≤ T, |s| ≤ 105 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 106 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ T, |s| ≤ 103 - 1 ≤ Sum of |s| over all test cases in a single test file ≤ 104 Subtask #2 (70 points) - Original constraints -----Example----- Input: 4 <<< <>< <=> <=< Output: 4 2 2 3 -----Explanation----- Here are some possible valid sequences which can be formed with the minimum P for each of the test cases: 1 < 2 < 3 < 4 1 < 2 > 1 < 2 1 < 2 = 2 > 1 1 < 2 = 2 < 3
n = int(input()) for i in range(n): k = 0 n1 = 0 p = 0 q = 0 lis = input() for j in lis: if j == "<": if k == 1: n1 += 1 if n1 > p: p = n1 else: n1 = 0 n1 += 1 if n1 > p: p = n1 k = 1 if j == ">": if k == 0: n1 += 1 if n1 > q: q = n1 else: n1 = 0 n1 += 1 if n1 > q: q = n1 k = 0 if p > q: print(p + 1) else: print(q + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR STRING IF VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR STRING IF VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Read problems statements in Mandarin Chinese and Russian as well. Given a sequence of n distinct numbers a[1..n], we want to sort them in an ascending order. An interesting property of some sequences is that all numbers are almost at their correct position! More formally, the distance between the current position of any value is at most 1 from its correct position in a sorted order. Now, you want to verify whether the input sequence has such a property. Note that the time limit for this problem is 0.2 seconds. Please try to write a very efficient algorithm and implementation. ------ Input ------ The first line contains an integer T denoting the total number of test cases. For each test case, the first line contains a single integer n, and the second line contains a[1..n] as a single space-separated list. ------ Output ------ For each test case, output "YES" or "NO" (without quotes) to indicate whether the input sequence has such a property. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ n ≤ 10^{6}$ $1 ≤ a[i] ≤ 10^{9}$ ----- Sample Input 1 ------ 2 3 1 2 3 5 2 4 1 3 5 ----- Sample Output 1 ------ YES NO
for i in range(int(input())): n = int(input()) a = list(map(int, input().split())) flag = 0 for j in range(n - 2): if a[j] > a[j + 1] and a[j] > a[j + 2]: print("NO") flag = 1 break if flag == 0: print("YES")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING
Read problems statements in Mandarin Chinese and Russian as well. Given a sequence of n distinct numbers a[1..n], we want to sort them in an ascending order. An interesting property of some sequences is that all numbers are almost at their correct position! More formally, the distance between the current position of any value is at most 1 from its correct position in a sorted order. Now, you want to verify whether the input sequence has such a property. Note that the time limit for this problem is 0.2 seconds. Please try to write a very efficient algorithm and implementation. ------ Input ------ The first line contains an integer T denoting the total number of test cases. For each test case, the first line contains a single integer n, and the second line contains a[1..n] as a single space-separated list. ------ Output ------ For each test case, output "YES" or "NO" (without quotes) to indicate whether the input sequence has such a property. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ n ≤ 10^{6}$ $1 ≤ a[i] ≤ 10^{9}$ ----- Sample Input 1 ------ 2 3 1 2 3 5 2 4 1 3 5 ----- Sample Output 1 ------ YES NO
t = int(input()) for _ in range(t): n = int(input()) l = [int(x) for x in input().split()] flag = True for i in range(n - 2): if l[i] > l[i + 2]: flag = False break if flag: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Read problems statements in Mandarin Chinese and Russian as well. Given a sequence of n distinct numbers a[1..n], we want to sort them in an ascending order. An interesting property of some sequences is that all numbers are almost at their correct position! More formally, the distance between the current position of any value is at most 1 from its correct position in a sorted order. Now, you want to verify whether the input sequence has such a property. Note that the time limit for this problem is 0.2 seconds. Please try to write a very efficient algorithm and implementation. ------ Input ------ The first line contains an integer T denoting the total number of test cases. For each test case, the first line contains a single integer n, and the second line contains a[1..n] as a single space-separated list. ------ Output ------ For each test case, output "YES" or "NO" (without quotes) to indicate whether the input sequence has such a property. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ n ≤ 10^{6}$ $1 ≤ a[i] ≤ 10^{9}$ ----- Sample Input 1 ------ 2 3 1 2 3 5 2 4 1 3 5 ----- Sample Output 1 ------ YES NO
def sorting(n, lst): count = 0 for i in range(n - 2): if lst[i] > lst[i + 1] and lst[i] > lst[i + 2]: count = 1 return "NO" if count == 0: return "YES" t = int(input()) for i in range(t): n = int(input()) lst = list(map(int, input().strip().split()))[:n] print(sorting(n, lst))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER RETURN STRING IF VAR NUMBER RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Read problems statements in Mandarin Chinese and Russian as well. Given a sequence of n distinct numbers a[1..n], we want to sort them in an ascending order. An interesting property of some sequences is that all numbers are almost at their correct position! More formally, the distance between the current position of any value is at most 1 from its correct position in a sorted order. Now, you want to verify whether the input sequence has such a property. Note that the time limit for this problem is 0.2 seconds. Please try to write a very efficient algorithm and implementation. ------ Input ------ The first line contains an integer T denoting the total number of test cases. For each test case, the first line contains a single integer n, and the second line contains a[1..n] as a single space-separated list. ------ Output ------ For each test case, output "YES" or "NO" (without quotes) to indicate whether the input sequence has such a property. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ n ≤ 10^{6}$ $1 ≤ a[i] ≤ 10^{9}$ ----- Sample Input 1 ------ 2 3 1 2 3 5 2 4 1 3 5 ----- Sample Output 1 ------ YES NO
t = int(input()) for _ in range(t): input() arr = [int(x) for x in input().strip().split()] flag = 0 result = "YES" for i in range(1, len(arr)): if arr[i - 1] > arr[i]: if flag == 1: result = "NO" break arr[i - 1], arr[i] = arr[i], arr[i - 1] flag = 1 else: flag = 0 print(result)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese and Russian as well. Given a sequence of n distinct numbers a[1..n], we want to sort them in an ascending order. An interesting property of some sequences is that all numbers are almost at their correct position! More formally, the distance between the current position of any value is at most 1 from its correct position in a sorted order. Now, you want to verify whether the input sequence has such a property. Note that the time limit for this problem is 0.2 seconds. Please try to write a very efficient algorithm and implementation. ------ Input ------ The first line contains an integer T denoting the total number of test cases. For each test case, the first line contains a single integer n, and the second line contains a[1..n] as a single space-separated list. ------ Output ------ For each test case, output "YES" or "NO" (without quotes) to indicate whether the input sequence has such a property. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ n ≤ 10^{6}$ $1 ≤ a[i] ≤ 10^{9}$ ----- Sample Input 1 ------ 2 3 1 2 3 5 2 4 1 3 5 ----- Sample Output 1 ------ YES NO
def Test(n, arr): last = arr[n - 1] flag = 0 for i in range(n - 2): if arr[i] > arr[i + 1] and arr[i] > arr[i + 2]: return "NO" return "YES" for _ in range(int(input())): n = int(input()) s = list(map(int, input().split())) print(Test(n, s))
FUNC_DEF ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER RETURN STRING RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Read problems statements in Mandarin Chinese and Russian as well. Given a sequence of n distinct numbers a[1..n], we want to sort them in an ascending order. An interesting property of some sequences is that all numbers are almost at their correct position! More formally, the distance between the current position of any value is at most 1 from its correct position in a sorted order. Now, you want to verify whether the input sequence has such a property. Note that the time limit for this problem is 0.2 seconds. Please try to write a very efficient algorithm and implementation. ------ Input ------ The first line contains an integer T denoting the total number of test cases. For each test case, the first line contains a single integer n, and the second line contains a[1..n] as a single space-separated list. ------ Output ------ For each test case, output "YES" or "NO" (without quotes) to indicate whether the input sequence has such a property. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ n ≤ 10^{6}$ $1 ≤ a[i] ≤ 10^{9}$ ----- Sample Input 1 ------ 2 3 1 2 3 5 2 4 1 3 5 ----- Sample Output 1 ------ YES NO
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) if n < 3: print("YES") else: f = 0 for i in range(n - 2): if a[i] > a[i + 1] and a[i] > a[i + 2]: f = 1 break if f == 0: print("YES") else: print("NO")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Read problems statements in Mandarin Chinese and Russian as well. Given a sequence of n distinct numbers a[1..n], we want to sort them in an ascending order. An interesting property of some sequences is that all numbers are almost at their correct position! More formally, the distance between the current position of any value is at most 1 from its correct position in a sorted order. Now, you want to verify whether the input sequence has such a property. Note that the time limit for this problem is 0.2 seconds. Please try to write a very efficient algorithm and implementation. ------ Input ------ The first line contains an integer T denoting the total number of test cases. For each test case, the first line contains a single integer n, and the second line contains a[1..n] as a single space-separated list. ------ Output ------ For each test case, output "YES" or "NO" (without quotes) to indicate whether the input sequence has such a property. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ n ≤ 10^{6}$ $1 ≤ a[i] ≤ 10^{9}$ ----- Sample Input 1 ------ 2 3 1 2 3 5 2 4 1 3 5 ----- Sample Output 1 ------ YES NO
def solve(): n = int(input()) s = list(map(int, input().strip().split()))[:n] for i in range(n - 2): if s[i] > s[i + 1] and s[i] > s[i + 2]: return "NO" return "YES" for _ in range(int(input())): print(solve())
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER RETURN STRING RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): l = [] n = len(s) if n == 1: return s i = 0 k = -1 while i < n: if k == -1: l.append(s[i]) k += 1 else: t = l[k] if t == s[i]: l.pop(k) k -= 1 else: l.append(s[i]) k += 1 i += 1 if k == -1: return "-1" else: r = "" for i in l: r += i return r
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN STRING ASSIGN VAR STRING FOR VAR VAR VAR VAR RETURN VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): i = 1 while i < len(s): if i == 0: i += 1 continue if s[i] == s[i - 1]: s = s[: i - 1] + s[i + 1 :] i -= 1 else: i += 1 if len(s) == 0: return -1 return s
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): lexp = list(s) stack = [] out = [] n = len(lexp) top = 0 stack.append(lexp[0]) for i in range(1, n): if len(stack) > 0: if lexp[i] != stack[top]: top += 1 stack.append(lexp[i]) elif lexp[i] == stack[top]: stack.pop() top -= 1 else: top += 1 stack.append(lexp[i]) if len(stack) == 0: return -1 else: return "".join(stack)
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN FUNC_CALL STRING VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): i = 0 s = s + "." ans = ["" for i in range(len(s))] ans1 = 0 while i < len(s) - 1: if s[i] == s[i + 1]: i += 2 else: ans[ans1] = s[i] ans1 += 1 if ans[ans1 - 1] == ans[ans1 - 2]: ans[ans1 - 1] = "" ans[ans1 - 2] = "" ans1 = ans1 - 2 i += 1 ans = "".join(ans) if ans == "": return "-1" else: return ans
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR IF VAR STRING RETURN STRING RETURN VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): l = [] for i in s: if len(l) == 0: l.append(i) elif l[-1] == i: l.pop() else: l.append(i) if len(l) == 0: return -1 else: return "".join(l)
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN FUNC_CALL STRING VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): st = [] for i in s: if st and st[-1] == i: st.pop() else: st.append(i) res = "".join(st) if not res: return -1 return res
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR IF VAR RETURN NUMBER RETURN VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): l = [] for i in s: if not l: l.append(i) elif l[-1] == i: l.pop() else: l.append(i) new = "".join(l) return new if new != "" else -1
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR RETURN VAR STRING VAR NUMBER
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): stack = [] i = 0 while i < len(s): if len(stack) == 0: stack.append(s[i]) elif s[i] == stack[-1]: stack.pop() else: stack.append(s[i]) i += 1 ans = "" while stack: a = stack.pop() ans = a + ans if ans == "": return -1 return ans
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR STRING WHILE VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR IF VAR STRING RETURN NUMBER RETURN VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): stack = [] for i in s: if len(stack) == 0: stack.append(i) elif stack[-1] == i: stack.pop(-1) else: stack.append(i) ans = "" for i in stack: ans += i if ans == "": return -1 return ans
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR VAR VAR VAR IF VAR STRING RETURN NUMBER RETURN VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): i = 0 a = list(s) c = len(a) s1 = "" j = 0 while i < c: if j == 0: s1 += s[i] j += 1 i += 1 else: s1 += s[i] j += 1 if s[i] == s1[j - 2]: if len(s1) == 2: s1 = "" else: s1 = s1[: len(s1) - 2] j -= 2 i += 1 if s1 == "": return "-1" else: return s1
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR IF VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR STRING RETURN STRING RETURN VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): stk = [] i = 0 ans = "" while i < len(s): if len(stk) == 0: stk.append(s[i]) i += 1 elif stk[-1] == s[i]: while len(stk) > 0 and i < len(s) and stk[-1] == s[i]: stk.pop() i += 1 if i == len(s): break else: stk.append(s[i]) i += 1 else: stk.append(s[i]) i += 1 if len(stk) == 0: return -1 while len(stk) != 0: ans += stk.pop() return ans[::-1]
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR RETURN VAR NUMBER
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): stack = [] i = 0 while i < len(s): if len(stack) > 0 and stack[-1] == s[i]: stack.pop() i += 1 else: stack.append(s[i]) i += 1 if len(stack) == 0: return -1 return "".join(stack)
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN FUNC_CALL STRING VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): n = len(s) ans, i = [s[0]], 1 while i < len(s): if len(ans) > 0: if s[i] == ans[-1]: ans.pop() n -= 2 else: ans.append(s[i]) else: ans.append(s[i]) i += 1 if n == 0: return -1 return "".join(ans)
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN FUNC_CALL STRING VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): stack = [] for ele in s: if len(stack) > 0: t = stack.pop() if t == ele: continue else: stack.append(t) stack.append(ele) else: stack.append(ele) if stack == []: return "-1" return "".join(stack)
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR LIST RETURN STRING RETURN FUNC_CALL STRING VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): stack = [] top = -1 for i in range(0, len(s)): if len(stack) == 0: stack.append(s[i]) top += 1 elif stack[top] != s[i]: stack.append(s[i]) top += 1 else: stack.pop() top -= 1 if len(stack) == 0: return -1 return "".join(stack)
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN FUNC_CALL STRING VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
import sys sys.setrecursionlimit(10**6) class Solution: def removePair(self, s): def solve(s): if len(s) == 0: return "" if len(s) == 1: return s if s[0] == s[1]: return solve(s[2:]) else: small = solve(s[1:]) if small and s[0] == small[0]: return small[1:] else: return s[0] + small return solve(s) if len(solve(s)) > 0 else -1
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN STRING IF FUNC_CALL VAR VAR NUMBER RETURN VAR IF VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER RETURN VAR NUMBER RETURN BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): l = [] for i in range(len(s)): if l and l[-1] == s[i]: l.pop() else: l.append(s[i]) if l: return "".join(l) else: return "-1"
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR IF VAR RETURN FUNC_CALL STRING VAR RETURN STRING
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): temp = [] for x in s[:]: if temp: if temp[-1] == x: temp.pop() else: temp.append(x) else: temp.append(x) return "".join(temp) if temp else -1
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_CALL STRING VAR NUMBER
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): arr = [] for i in s: if arr and arr[-1] == i: arr.pop() else: arr.append(i) return "".join(arr) if arr else "-1"
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_CALL STRING VAR STRING
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): stack = [] stack.append(s[0]) curr_index = 1 while curr_index < len(s): if len(stack) == 0: stack.append(s[curr_index]) elif s[curr_index] == stack[-1]: stack.pop() else: stack.append(s[curr_index]) curr_index += 1 ans = "" for char in stack: ans += char if len(ans) == 0: ans = "-1" return ans
CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING RETURN VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): stk = [] for char in s: if not stk: stk.append(char) continue if stk[-1] == char: stk.pop() else: stk.append(char) if not stk: return -1 return "".join(stk)
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR RETURN NUMBER RETURN FUNC_CALL STRING VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): i = 1 s = list(s) A = [s[0]] for i in range(1, len(s)): if len(A) == 0: A.append(s[i]) elif s[i] == A[-1]: A.pop() else: A.append(s[i]) if len(A) == 0: return -1 return "".join(A)
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN FUNC_CALL STRING VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): flag = False while flag == False: for i in range(1, len(s)): if s[i - 1] == s[i]: s = s.replace(s[i - 1] + s[i], "") flag = True break if flag == True: flag = False else: break if s: return s return -1
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR RETURN VAR RETURN NUMBER
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): stack = [] for i in range(len(s)): if not stack: stack.append(s[i]) elif stack and s[i] == stack[-1]: stack.pop() else: stack.append(s[i]) return "".join(stack) if stack else -1
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_CALL STRING VAR NUMBER
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): stack = [] for i in s: if stack and stack[-1] == i: stack.pop() else: stack.append(i) c = "" if not stack: return -1 while stack: c += stack.pop() c = c[::-1] return c
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING IF VAR RETURN NUMBER WHILE VAR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER RETURN VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
def merge(s1, s2): while s1 and s2: if s1[-1] == s2[0]: s1.pop(-1) s2.pop(0) else: break return s1 + s2 def break_pair(s): if len(s) == 1: return s else: mid = len(s) // 2 s1 = break_pair(s[:mid]) s2 = break_pair(s[mid:]) s_final = merge(s1, s2) return s_final class Solution: def removePair(self, s): a = list(s) res = break_pair(a) return "".join(res) if res else -1
FUNC_DEF WHILE VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN BIN_OP VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR FUNC_CALL STRING VAR NUMBER
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): stk = [-1] top = 0 for i in s: if stk[top] == i: stk.pop(top) top -= 1 else: top += 1 stk.append(i) if len(stk) == 1: return -1 else: st = "" l = len(stk) for i in range(1, l): st += stk[i] return st
CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR RETURN VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): i = 0 while i < len(s) - 1: if s[i] == s[i + 1]: s = s[:i] + s[i + 2 :] i = -1 i += 1 if len(s) == 0: return "-1" return s
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN STRING RETURN VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): stack = [] n = len(s) count = 0 for i in range(n): if stack == []: stack = [s[i]] count += 1 elif stack[-1] == s[i]: stack.pop() count -= 1 while count >= 2: if stack[-1] == stack[-2]: stack.pop() stack.pop() count -= 2 else: break else: stack.append(s[i]) count += 1 if count == 0: return -1 return "".join(stack)
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR LIST ASSIGN VAR LIST VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN FUNC_CALL STRING VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): fg = [] res = "" for i in s: f = 0 while len(fg) > 0 and fg[len(fg) - 1] == i: fg.pop(len(fg) - 1) f = 1 if f == 0: fg.append(i) while len(fg) > 0: res = fg[len(fg) - 1] + res fg.pop(len(fg) - 1) if len(res) == 0: return "-1" return res
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN STRING RETURN VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): lst = [] lst.append("@") for i in s: if lst[len(lst) - 1] != i: lst.append(i) else: lst.pop() if len(lst) == 1: return -1 kk = "" for i in range(1, len(lst)): kk += lst[i] return kk
CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR STRING FOR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): s1 = s while True: isRemoved = False for idx in range(len(s) - 1): if s[idx] == s[idx + 1]: text2Remove = s[idx] + s[idx + 1] s1 = s1.replace(text2Remove, "", 1) isRemoved = True if isRemoved == False: break else: s = s1 if len(s1) == 0: return -1 else: return s1
CLASS_DEF FUNC_DEF ASSIGN VAR VAR WHILE NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): i = 0 s = list(s) while i < len(s) - 1 and len(s) != 0: if s[i] == s[i + 1]: s.pop(i) s.pop(i) i = -1 i += 1 if len(s) == 0: return "-1" return "".join(s)
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN STRING RETURN FUNC_CALL STRING VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): l = [] for i in s: if not l: l.append(i) elif l[len(l) - 1] == i: l.pop() else: l.append(i) k = "" if not l: return -1 for i in l: k += i return k
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING IF VAR RETURN NUMBER FOR VAR VAR VAR VAR RETURN VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): stack = [" "] * len(s) top = -1 for x in s: if top == -1 or stack[top] != x: top += 1 stack[top] = x elif x == stack[top]: top -= 1 s = "" for i in range(0, top + 1): s = s + stack[i] if top == -1: return -1 return s
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): st = [] i = 0 while i < len(s): if len(st) == 0 or st[-1] != s[i]: st.append(s[i]) elif len(st) != 0 and st[-1] == s[i]: st.pop() i += 1 t = "" for j in st: t += j if t == "": return -1 return t
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR VAR IF VAR STRING RETURN NUMBER RETURN VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): ans = "" st = ["0", s[0]] l = len(s) for i in range(1, l): if st[-1] == s[i]: st.pop() flag = True else: st.append(s[i]) if st != ["0"]: ans = "".join(st[1:]) else: ans = -1 return ans
CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR LIST STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR LIST STRING ASSIGN VAR FUNC_CALL STRING VAR NUMBER ASSIGN VAR NUMBER RETURN VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): l = [] l.append(s[0]) for i in range(1, len(s)): try: if l[-1] == s[i]: l.pop() else: l.append(s[i]) except IndexError: l.append(s[i]) if len(l) == 0: return -1 return "".join(l)
CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN FUNC_CALL STRING VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): i = 0 ans = "" while i < len(s): if i + 1 >= len(s): if s: return s else: return -1 if s[i + 1] == s[i]: count = 0 temp = s[i] j = i while j < len(s) and temp == s[j]: count += 1 j += 1 if count % 2 != 0: s = s[:i] + s[j - 1 :] if i != 0: i -= 1 continue else: s = s[:i] + s[j:] if i != 0: i -= 1 continue i += 1 if s: return s else: return -1
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR RETURN VAR RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR RETURN VAR RETURN NUMBER
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): new_s = [] l = 0 b = -1 while l < len(s) - 1: if s[l] == s[l + 1]: l += 2 elif b != -1 and s[l] == new_s[b]: new_s.pop() b -= 1 l += 1 else: new_s.append(s[l]) b += 1 l += 1 if l < len(s): if b != -1 and s[l] == new_s[b]: new_s.pop() b -= 1 else: new_s.append(s[l]) if b == -1: return b else: return "".join(new_s)
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN VAR RETURN FUNC_CALL STRING VAR
Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by recursively removing all the consecutive duplicate pairs. In other words, He can apply the below operations any number of times. Remove all the consecutive duplicate pairs and concatenate the remaining string to replace the original string. Your task is to find the string with minimum length after applying the above operations. Note: If the string length become zero after applying operations, return "-1" as a string. Example 1: Input: aaabbaaccd Output: ad Explanation: Remove (aa)abbaaccd =>abbaaccd Remove a(bb)aaccd => aaaccd Remove (aa)accd => accd Remove a(cc)d => ad Example 2: Input: aaaa Output: Empty String Explanation: Remove (aa)aa => aa Again removing pair of duplicates then (aa) will be removed and we will get 'Empty String'. Your Task: This is a function problem. You only need to complete the function removePair() that takes a string as a parameter and returns the modified string. Return "-1" if the whole string is deleted. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 <= |str| <= 10^{4}
class Solution: def removePair(self, s): st = [] i = 0 while i < len(s): if len(st) == 0 or s[i] != st[-1]: st.append(s[i]) i += 1 else: st.pop() i += 1 else: short_string = "" for i in st: short_string += str(i) if len(short_string) == 0: return -1 else: return short_string
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN VAR