code
stringlengths
46
24k
language
stringclasses
6 values
AST_depth
int64
3
30
alphanumeric_fraction
float64
0.2
0.75
max_line_length
int64
13
399
avg_line_length
float64
5.01
139
num_lines
int64
7
299
task
stringlengths
151
14k
source
stringclasses
3 values
n = int(input()) m = list(map(int, input().split())) a = [0] * n k = 0 for i in range(n): k = max(k, m[i] + 1) a[i] = k for i in range(n - 1, 0, -1): a[i - 1] = max(a[i] - 1, a[i - 1]) ans = 0 for i in range(n): ans += a[i] - m[i] - 1 print(ans)
python
11
0.468
35
18.230769
13
Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value. Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to mi. Define di as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of di over all days. There are no marks on the channel before the first day. Input The first line contains a single positive integer n (1 ≀ n ≀ 105) β€” the number of days. The second line contains n space-separated integers m1, m2, ..., mn (0 ≀ mi < i) β€” the number of marks strictly above the water on each day. Output Output one single integer β€” the minimum possible sum of the number of marks strictly below the water level among all days. Examples Input 6 0 1 0 3 0 2 Output 6 Input 5 0 1 2 1 2 Output 1 Input 5 0 1 1 2 2 Output 0 Note In the first example, the following figure shows an optimal case. <image> Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6. In the second example, the following figure shows an optimal case. <image>
taco
s = input().lower() vow = ['a', 'e', 'i', 'o', 'u', 'y'] ans = '' for ch in s: if ch in vow: continue if ch.isalpha(): ans += '.' + ch print(ans)
python
9
0.473684
36
15.888889
9
Tom has finally taken over the business empire and now looking for a new Name of the business to make a new start. Joe (Tom's dear friend) suggested a string $S$ consisting of Uppercase and lowercase letters Tom wants to make some changes as per the following criteria: 1) String should $not$ have any vowels . 2) Every other uppercase consonant(other characters except vowels) should be in lowercase For ex: If the consonant character is Z then it should be z 3) There should be a character "." before each consonant. Help Tom to make the required Changes. -----Input:----- - First line will contain string $S$,This string only consists of uppercase and lowercase letters. -----Output:----- Print the resulting string. It is guaranteed that this string is not empty. -----Constraints----- - Length of string is in [1 .. 100] -----Sample Input:----- $CodeSprInT$ -----Sample Output:----- .c.d.s.p.r.n.t -----EXPLANATION:----- C is a consonant and it is in uppercase so turn it in lower case and add a β€œ.” before it o is a vowel so it is deleted d is a consonant and in lowercase so just add a β€œ.” before it e is a vowel so it is deleted S is a consonant and it is in uppercase so turn it in lower case and add a β€œ.” before it p is a consonant and in lowercase so just add a β€œ.” before it r is a consonant and in lowercase so just add a β€œ.” before it I is a vowel so it is deleted n is a consonant and in lowercase so just add a β€œ.” before it T is a consonant and it is in uppercase so turn it in lower case and add a β€œ.” before it
taco
for i in range(0, int(input())): n = int(input()) l = list(input()) t = 0 a = 0 b = 0 for j in range(0, n): t = t + 1 if l[j] == '0': a = a + 1 else: b = b + 1 if b >= t / 2: print('YES') break elif j == n - 1 and b < t / 2: print('NO') else: continue
python
12
0.4375
32
14.157895
19
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
for _ in range(int(input())): n = int(input()) s = input() (c, c1) = (0, 0) ans = 'NO' for i in s: if i == '1': c1 += 1 c += 1 if c1 * 2 >= c: ans = 'YES' break print(ans)
python
10
0.435233
29
13.846154
13
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
t = int(input()) for ni in range(t): l = int(input()) s = input() (s0, s1) = (0, 0) pos = 'NO' for i in range(len(s)): if s[i] == '0': s0 = s0 + 1 else: s1 = s1 + 1 if s1 >= s0: pos = 'YES' break print(pos)
python
11
0.463203
24
14.4
15
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
t = int(input()) while t: l = int(input()) s = input() if s.count('1') >= s.count('0'): print('YES') else: a = 0 flag = False for i in range(0, l): if s[i] == '1': a += 1 if a >= (i + 1) / 2: flag = True break if flag == True: print('YES') else: print('NO') t -= 1
python
15
0.449838
33
14.45
20
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
a = int(input('')) for i in range(a): x = int(input('')) t = input('') c1 = 0 c0 = 0 flag = 0 for j in range(len(t)): if t[j] == '1': c1 = c1 + 1 else: c0 = c0 + 1 if c1 >= c0: flag = 1 print('YES' if flag else 'NO')
python
11
0.468619
31
14.933333
15
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
for _ in range(int(input())): n = int(input()) s = input() count1 = 0 count0 = 0 flag = 0 for i in range(len(s)): if s[i] == '1': count1 += 1 else: count0 += 1 if count1 >= count0: flag = 1 print('YES' if flag else 'NO')
python
10
0.530864
31
16.357143
14
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
t = int(input()) for i in range(t): L = int(input()) S = input() b = 0 g = 0 flag = 0 for j in range(L): if S[j] == '0': b = b + 1 elif S[j] == '1': g = g + 1 if g >= b: flag = 1 break if flag == 0: print('NO') else: print('YES')
python
11
0.442308
19
12.684211
19
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
t = int(input()) for t in range(t): l = int(input()) s = input() count_0 = 0 count_1 = 0 flag = 0 for i in range(len(s)): if s[i] == '0': count_0 += 1 else: count_1 += 1 if count_1 >= count_0 and count_0 != 0 or (count_0 == 0 and count_1 > 0): flag = 1 break if flag == 0: print('NO') else: print('YES')
python
10
0.51497
75
16.578947
19
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
for _ in range(int(input())): L = int(input()) S = input().strip() if S.count('1') >= L // 2 + (L % 2 > 0): print('YES') continue count = 0 yrs = 0 for c in S: count += c == '1' yrs += 1 if count >= yrs // 2 + (yrs % 2 > 0): print('YES') break else: print('NO')
python
11
0.473868
41
16.9375
16
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
for tc in range(int(input())): L = int(input()) S = input() (g, t) = (0, 0) ans = 'NO' for i in S: t += 1 if i == '1': g += 1 if g / t >= 0.5: ans = 'YES' break else: ans = 'NO' print(ans)
python
11
0.432558
30
13.333333
15
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
import re for i in range(int(input())): l = int(input()) str1 = input() sum1 = 0 sum2 = 0 if str1[0] == '1': print('YES') else: for i in str1: if i == '0': sum1 = sum1 + 1 else: sum2 = sum2 + 1 if sum2 >= sum1: print('YES') break elif sum2 + sum1 == len(str1): print('NO')
python
15
0.507937
33
15.578947
19
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
t = int(input()) for i in range(t): l = int(input()) s = input() flag = 0 (count1, count2) = (0, 0) for i in s: if i == '0': count1 += 1 else: count2 += 1 if count2 >= count1: flag = 1 break if flag: print('YES') else: print('NO')
python
10
0.511538
26
13.444444
18
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
t = int(input()) while t != 0: n = int(input()) s = input() c = 0 f = 0 for k in range(n): if s[k] == '1': c += 1 if c >= (k + 1) / 2: f = 1 break if f == 1: print('YES') else: print('NO') t -= 1
python
12
0.410714
23
12.176471
17
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
for _ in range(int(input())): n = int(input()) s = input() (o, z) = (0, 0) c = 'NO' for i in s: if i == '0': z += 1 else: o += 1 if o >= z: c = 'YES' break print(c)
python
13
0.40625
29
12.714286
14
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
for _ in range(int(input())): l = int(input()) s = input() z = 0 o = 0 ans = 'NO' for c in s: if c == '0': z += 1 else: o += 1 if o >= z: ans = 'YES' break print(ans)
python
13
0.430769
29
12
15
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
for i in range(int(input())): a = int(input()) s = input() c = d = 0 for i in range(len(s)): if s[i] == '1': c += 1 if c * 100 / (i + 1) >= 50: print('YES') break else: print('NO')
python
11
0.462687
29
15.75
12
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
import math for i in range(int(input())): n = int(input()) s = input() c = 0 if s.count('1') >= s.count('0'): print('YES') else: o = 0 z = 0 for i in s: if i == '1': o += 1 else: z += 1 if o == z: c += 1 print('YES') break if c == 0: print('NO')
python
14
0.433447
33
12.952381
21
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
t = int(input()) for _ in range(t): l = int(input()) s = input() cntz = 0 cnto = 0 t = True for i in range(l): if s[i] == '0': cntz += 1 if s[i] == '1': cnto += 1 if cntz == cnto: t = False break if cntz < cnto or not t: print('YES') else: print('NO')
python
10
0.489362
25
13.842105
19
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
T = int(input()) for _ in range(T): L = int(input()) S = input() zeros = 0 ones = 0 flag = False for i in S: if i == '1': ones += 1 else: zeros += 1 if ones >= zeros: flag = True break print('YES' if flag else 'NO')
python
10
0.518672
31
14.0625
16
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
for i in range(int(input())): a = int(input()) b = input() ch = 0 bj = 0 for i in range(1, a + 1): if b[i - 1] == '1': ch += 1 if ch / i >= 0.5: bj += 1 break if bj == 1: print('YES') else: print('NO')
python
10
0.451327
29
14.066667
15
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
t = int(input()) for k in range(t): n = int(input()) a = str(input()) b = 0 c = 0 d = 0 while b != len(a): if a[b] == '0': c += 1 else: d += 1 b += 1 if c <= d: b = len(a) if c <= d: print('YES') else: print('NO')
python
11
0.419753
19
11.789474
19
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
T = int(input()) for i in range(T): L = int(input()) S = input() c = 0 li = [] for j in S: li.append(j) for i in range(L): if li[i] == '1': c = c + 1 if c * 100 / (i + 1) >= 50: z = c * 100 / (i + 1) break else: z = c * 100 / (i + 1) print('YES' if z >= 50 else 'NO')
python
13
0.437288
34
16.352941
17
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
for _ in range(int(input())): n = int(input()) s = input() one = 0 chk = 0 for i in range(1, n + 1): if s[i - 1] == '1': one += 1 if one / i >= 0.5: chk = 1 break if chk == 1: print('YES') else: print('NO')
python
10
0.463203
29
14.4
15
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
for i in range(int(input())): l = int(input()) s = input() good = s.count('1') bad = s.count('0') if good >= len(s) / 2: print('YES') else: (cb, cg, flag) = (0, 0, False) for i in s: if i == '1': cg += 1 else: cb += 1 if cg >= cb: print('YES') flag = True break if flag == False: print('NO')
python
14
0.470414
32
15.9
20
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
t = int(input()) for i in range(t): l = int(input()) s = input() c = 0 d = 0 ans = False for i in s: if i == '0': c += 1 else: d += 1 if c <= d: ans = True break if ans: print('YES') else: print('NO')
python
10
0.463203
18
11.157895
19
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
for _ in range(int(input())): n = int(input()) s = input() heaven = False one = 0 total = 0 for i in s: if i == '1': one += 1 total += 1 if 2 * one >= total: heaven = True break else: total += 1 if heaven: print('YES') else: print('NO')
python
11
0.505495
29
13.368421
19
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
t = int(input()) for i in range(t): n = int(input()) st = input() g = 0 b = 0 d = 0 for i in st: if i == '0': b = b + 1 else: g = g + 1 if g >= b: print('YES') d = d + 1 break if d == 0: print('NO')
python
11
0.419214
18
11.722222
18
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
for _ in range(int(input())): l = int(input()) s = input() c = 0 c1 = 0 x = 0 for i in range(l): if s[i] == '0': c += 1 else: c1 += 1 if c1 >= c: x = i + 1 break if x == 0: print('NO') else: print('YES')
python
10
0.435897
29
12
18
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
q = int(input()) while q > 0: q -= 1 n = int(input()) l = input() count = 0 flag = 0 for i in range(0, n): if l[i] == '1': count += 1 if count / (i + 1) * 100 >= 50: flag = 1 break if flag == 0: print('NO') else: print('YES')
python
11
0.47012
33
13.764706
17
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
for t in range(int(input())): l = input() s = input() one = 0 zero = 0 c = 0 for i in s: if i == '1': one = one + 1 else: zero = zero + 1 if one >= zero: c = c + 1 print('YES') break if c == 0: print('NO')
python
11
0.461864
29
12.882353
17
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
tests = int(input()) for i in range(tests): length = int(input()) string = input() ans = 'NO' zeroes = 0 ones = 0 for j in string: if j == '0': zeroes += 1 else: ones += 1 if ones >= zeroes: ans = 'YES' break print(ans)
python
10
0.546939
22
14.3125
16
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
for _ in range(int(input())): n = int(input()) s = input() (x, y) = (0, 0) for i in s: if i == '1': x += 1 else: y += 1 if x >= y: print('YES') break else: print('NO')
python
11
0.435233
29
12.785714
14
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
for _ in range(int(input())): n = int(input()) s = input() (a, b) = (0, 0) for i in s: if i == '1': a += 1 else: b += 1 if a >= b: print('YES') break else: print('NO')
python
11
0.435233
29
12.785714
14
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
T = int(input()) def algo(): L = int(input()) S = input() b = 0 g = 0 out = 0 for i in S: if i == '0': b += 1 else: g += 1 if g >= b: out = 1 break if out == 1: print('YES') else: print('NO') for i in range(T): algo()
python
12
0.442688
18
10.5
22
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
T = int(input()) for i in range(T): n = int(input()) l = str(input()) bad = 0 good = 0 p = False for z in l: if z == '1': good += 1 else: bad += 1 if good >= bad: p = True if p: print('YES') else: print('NO')
python
10
0.483051
18
12.111111
18
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
from sys import stdin for _ in range(int(stdin.readline())): n = int(stdin.readline()) s = stdin.readline().strip() q = 0 for c in s: q += -1 if c == '0' else 1 if q >= 0: break print('NO' if q < 0 else 'YES')
python
10
0.572072
38
21.2
10
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
for _ in range(int(input())): n = int(input()) s = input() (c1, c2, f) = (0, 0, 0) for i in s: if i == '0': c1 += 1 else: c2 += 1 if c2 >= c1: print('YES') f = 1 break if f == 0: print('NO')
python
11
0.429224
29
13.6
15
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
t = int(input()) while t: t -= 1 n = int(input()) s = input() count0 = 0 count1 = 0 f = 0 for i in s: if i == '0': count0 += 1 else: count1 += 1 if count1 >= count0: print('YES') f = 1 break if f == 0: print('NO')
python
11
0.477551
22
11.894737
19
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
for i in range(int(input())): L = int(input()) S = str(input()) Y = 0 flag = False if S.count('1') >= L / 2: flag = True else: for ii in range(L): Y = Y + int(S[ii]) if Y / (ii + 1) >= 0.5: flag = True break print('YES') if flag else print('NO')
python
14
0.509225
38
18.357143
14
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
for _ in range(int(input())): N = int(input()) S = input() (One, zero) = (0, 0) flag = False for i in range(N): if S[i] == '0': zero += 1 else: One += 1 if One >= zero: flag = True break if flag: print('YES') else: print('NO')
python
10
0.5
29
14.058824
17
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
t = int(input()) for i in range(t): l = int(input()) s = input() h = [] hl = [] for j in s: if j == '0': hl.append(j) else: h.append(j) if len(h) >= len(hl): print('YES') break else: print('NO')
python
11
0.479638
23
12.8125
16
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
t = int(input()) for i in range(t): L = int(input()) S = input() good = 0 bad = 0 poss = False for i in range(L): if S[i] == '1': good += 1 else: bad += 1 if good >= bad: poss = True if poss: print('YES') else: print('NO')
python
10
0.504
19
12.888889
18
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
for i in range(int(input())): l = int(input()) s = input() x = 'NO' g = 0 b = 0 if s.count('1') >= l / 2: x = 'YES' else: for i in s: if g >= b and g != 0: x = 'YES' break elif i == '1': g += 1 else: b += 1 print(x)
python
13
0.41502
29
13.055556
18
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
t = int(input()) for _ in range(t): n = int(input()) life = str(input()) count = 0 if life.count('1') >= life.count('0'): print('YES') else: i = 0 while i < n: if life[i] == '0': count = count - 1 else: count = count + 1 if count >= 0: break i = i + 1 if count >= 0: print('YES') else: print('NO')
python
14
0.484058
39
15.428571
21
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
for i in range(int(input())): L = int(input()) s = input() ones = 0 zeros = 0 for j in range(len(s)): if s[j] == '0': zeros += 1 else: ones += 1 if ones >= zeros: print('YES') break else: print('NO')
python
11
0.50885
29
14.066667
15
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
t = int(input()) while t > 0: l = int(input()) s = input() i = 0 flg = 0 c0 = 0 c1 = 0 while i < l: if s[i] == '1': c1 += 1 if c1 * 100 / (i + 1) >= 50: flg = 1 print('YES') break i += 1 if flg == 0: print('NO') t -= 1
python
13
0.40873
31
12.263158
19
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
for _ in range(int(input())): L = int(input()) S = input() bad = 0 good = 0 for i in range(L): if i != 0 and bad <= good: break if S[i] == '0': bad += 1 else: good += 1 if bad <= good: print('YES') else: print('NO')
python
10
0.491736
29
14.125
16
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
import math for _ in range(int(input())): n = int(input()) s = input() l = 0 c = 0 for i in range(n): if i != 0 and l <= c: break elif s[i] == '0': l += 1 else: c += 1 if l <= c: print('YES') else: print('NO')
python
10
0.470339
29
12.882353
17
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
t = int(input()) for i in range(t): g = 0 b = 0 ded = True l = int(input()) s = input() for j in s: ded = True if j == '1': g += 1 if g >= b: print('YES') ded = False break elif j == '0': b += 1 if g >= b: print('YES') ded = False break if ded: print('NO')
python
14
0.444805
18
12.391304
23
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
t = int(input()) while t > 0: n = int(input()) strg = list(input()) count_zero = 0 for i in range(n): var = 'NO' if strg[i] == '0': count_zero += 1 if i + 1 - count_zero >= count_zero: var = 'YES' break print(var) t -= 1
python
10
0.520661
38
16.285714
14
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
testcasenum = int(input()) def heaven(deeds): good_deeds = 0 bad_deeds = 0 for i in range(len(deeds)): if deeds[i] == 1: good_deeds += 1 elif deeds[i] == 0: bad_deeds += 1 if good_deeds >= bad_deeds: return 'YES' return 'NO' for __ in range(testcasenum): life = int(input()) deeds = list(map(int, list(input()))) result = heaven(deeds) print(result)
python
13
0.617647
38
19.777778
18
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
n = int(input()) num = [] dt = [] for i in range(0, n): num.append(int(input())) dt.append(input()) for j in range(0, n): pas = 0 gd = 0 bd = 0 lst = list(dt[j]) for k in range(0, num[j]): if lst[k] == '0': bd = bd + 1 else: gd = gd + 1 if gd >= bd: pas = pas + 1 if pas == 0: print('NO') else: print('YES')
python
11
0.491071
27
14.272727
22
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
for i in range(int(input())): l = 0 c = 0 j = int(input()) st = input() for i in range(0, len(st)): if i != 0 and l <= c: break elif st[i] == '0': l = l + 1 else: c = c + 1 if l <= c: print('YES') else: print('NO')
python
11
0.460581
29
14.0625
16
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
for _ in range(int(input())): a = int(input()) b = input() g = 0 p = 0 k = 0 for i in b: if i == '1': g += 1 if i == '0': p += 1 if g >= p: print('YES') k = 1 break if k == 0: print('NO')
python
11
0.40367
29
11.823529
17
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
T = int(input()) for i in range(T): L = int(input()) S = input() count = 0 count1 = 0 for j in S: if int(j) == 1: count += 1 else: count1 += 1 if count >= count1: print('YES') break if count1 > count: print('NO')
python
11
0.527197
21
13.9375
16
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
t = int(input()) while t > 0: l = int(input()) s = input() countz = 0 counto = 0 for i in range(0, len(s)): if s[i] == '0': countz = countz + 1 else: counto = counto + 1 if counto >= countz: print('YES') break if countz > counto: print('NO') t = t - 1
python
11
0.526882
27
15.411765
17
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
def main(): for _ in range(int(input())): L = int(input()) S = input() (gy, by) = (0, 0) ans = 'NO' for i in range(L): if S[i] == '1': gy += 1 else: by += 1 if gy >= by: ans = 'YES' break print(ans) main()
python
12
0.438525
30
14.25
16
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
t = int(input()) for i in range(t): L = int(input()) S = input() total1 = 0 total2 = 0 flag = 0 for i in range(L): if S[i] == '0': total1 += 1 else: total2 += 1 if total2 >= total1: flag = 1 print('YES') break if flag == 0: print('NO')
python
14
0.503704
23
14
18
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
class Person: def __init__(self, deed): self.deed = deed def good_deed(self): self.deed += 1 def bad_deed(self): self.deed -= 1 person = Person(1) t = int(input()) while t: t -= 1 n = int(input()) s = input() person.deed = 1 for i in s: if i == '0': person.bad_deed() else: person.good_deed() if person.deed > 0: break if person.deed > 0: print('YES') else: print('NO')
python
11
0.571078
26
13.571429
28
When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good. Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1≀ L'≀ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so. Tell whether Chef can go to heaven. ------ Input ------ The first line contains an integer $T$, the number of test cases. Then the test cases follow. Each test case contains two lines of input. The first line contains a single integer $L$. The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1. ------ Output ------ For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes). You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). ------ Constraints ------ $1 ≀ L ≀ 10^{5}$ The sum of $L$ over all tests does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 3 2 10 3 001 4 0100 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. Test case 2: There's no way Chef can go to heaven. Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
taco
class Solution: def findSubString(self, str): dict = {} ans = float('inf') j = 0 for i in str: if i not in dict: dict[i] = 0 length = len(dict) for i in range(len(str)): dict[str[i]] += 1 if dict[str[i]] == 1: length -= 1 while length == 0: ans = min(ans, i - j + 1) dict[str[j]] -= 1 if dict[str[j]] == 0: length += 1 j += 1 return ans
python
15
0.505076
30
17.761905
21
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
from collections import defaultdict class Solution: def findSubString(self, s): n = len(s) dist_count = len(set([x for x in s])) m = defaultdict(int) start = 0 min_len = float('inf') count = 0 for j in range(n): m[s[j]] += 1 if m[s[j]] == 1: count += 1 if count == dist_count: while m[s[start]] > 1: if m[s[start]] > 1: m[s[start]] -= 1 start += 1 len_window = j - start + 1 if min_len > len_window: min_len = len_window return min_len
python
17
0.550898
39
19.875
24
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
class Solution: def findSubString(self, str): from collections import defaultdict n = len(str) if n <= 1: return 1 dist_count = len(set([x for x in str])) curr_count = defaultdict(lambda : 0) count = 0 start = 0 min_len = n for j in range(n): curr_count[str[j]] += 1 if curr_count[str[j]] == 1: count += 1 if count == dist_count: while curr_count[str[start]] > 1: if curr_count[str[start]] > 1: curr_count[str[start]] -= 1 start += 1 len_window = j - start + 1 min_len = min(min_len, len_window) start_index = start return min_len
python
17
0.590682
41
23.04
25
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
class Solution: def findSubString(self, s): D = {} for i in s: if i in D: pass else: D[i] = 1 n = len(s) (i, j) = (0, 0) count = len(D) mini = 9999 while j < n: if s[j] in D: D[s[j]] -= 1 if D[s[j]] == 0: count -= 1 while count == 0: mini = min(mini, j - i + 1) if s[i] in D: D[s[i]] += 1 if D[s[i]] > 0: count += 1 i += 1 j += 1 return mini
python
15
0.417453
31
14.703704
27
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
class Solution: def findSubString(self, str): mp = {} cnt = 0 for i in range(len(str)): if str[i] not in mp: mp[str[i]] = 0 cnt += 1 cnt1 = 0 j = 0 mn = len(str) for i in range(len(str)): if mp[str[i]] == 0: mp[str[i]] += 1 cnt1 += 1 else: mp[str[i]] += 1 while cnt == cnt1: mn = min(mn, i - j + 1) if mp[str[j]] == 1: mp[str[j]] -= 1 cnt1 -= 1 j = j + 1 else: mp[str[j]] -= 1 j = j + 1 return mn
python
16
0.444215
30
16.285714
28
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
class Solution: def findSubString(self, str): dict = {} a = 1000000000.0 j = 0 for i in str: if i not in dict: dict[i] = 0 l = len(dict) for i in range(len(str)): dict[str[i]] += 1 if dict[str[i]] == 1: l -= 1 while l == 0: a = min(a, i - j + 1) dict[str[j]] -= 1 if dict[str[j]] == 0: l += 1 j += 1 return a
python
15
0.47541
30
16.428571
21
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
class Solution: def findSubString(self, s): distinct = len(set(s)) d = dict() si = -1 Len = 100000.0 start = 0 for i in range(len(s)): if s[i] not in d: d[s[i]] = 1 else: d[s[i]] += 1 if len(d) == distinct: while d[s[start]] > 1: d[s[start]] -= 1 start += 1 clen = i - start + 1 if Len > clen: Len = clen si = start return len(s[si:si + Len])
python
15
0.495098
28
17.545455
22
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
from collections import defaultdict class Solution: def findSubString(self, str): leng = len(str) (start, end) = (0, leng - 1) ct = 0 t_dist = len(set([e for e in str])) chr_map = defaultdict(lambda : 0) min_wind = leng for i in range(leng): x = str[i] chr_map[x] += 1 if chr_map[x] == 1: ct += 1 if ct == t_dist: while chr_map[str[start]] > 1: chr_map[str[start]] -= 1 start += 1 min_wind = min(i - start + 1, min_wind) return min_wind
python
15
0.569388
43
21.272727
22
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
class Solution: def findSubString(self, str): n = len(str) (dic, vic) = ({}, {}) for a in str: if a not in dic: dic[a] = 0 dic[a] += 1 (i, j, ans) = (0, 0, 10000000000) while j < n: if str[j] not in vic: vic[str[j]] = 0 vic[str[j]] += 1 if len(vic) == len(dic): while len(vic) == len(dic): vic[str[i]] -= 1 if vic[str[i]] == 0: del vic[str[i]] i += 1 ans = min(ans, 2 + j - i) j += 1 return ans
python
16
0.469828
35
19.173913
23
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
class Solution: def findSubString(self, str): dict = {} ans = 1000000000.0 for i in str: if i not in dict: dict[i] = 0 length = len(dict) count = 0 j = 0 for i in range(len(str)): dict[str[i]] += 1 if dict[str[i]] == 1: count += 1 while count == length: ans = min(ans, i - j + 1) dict[str[j]] -= 1 if dict[str[j]] == 0: count -= 1 j += 1 return ans
python
15
0.514706
30
17.545455
22
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
from collections import Counter class Solution: def findSubString(self, str1): length = len(str1) dict1 = Counter(str1) k = len(dict1) dict2 = dict() count = 0 start = 0 minimum = 99999 for i in range(length): if count < k: j = start while j < length: if str1[j] not in dict2: dict2[str1[j]] = 1 count += 1 else: dict2[str1[j]] += 1 if count == k: break j += 1 if count == k: minimum = min(minimum, j - i + 1) start = j + 1 dict2[str1[i]] -= 1 if dict2[str1[i]] == 0: dict2.pop(str1[i]) count -= 1 return minimum
python
18
0.543974
37
18.1875
32
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
from collections import Counter, defaultdict class Solution: def findSubString(self, str_): set_of_string = set() len_set_of_string = len(set(str_)) answer = float('inf') left = 0 right = 0 freq = defaultdict(int) while right < len(str_): freq[str_[right]] += 1 while left <= right and len(freq) == len_set_of_string: answer = min(answer, right - left + 1) freq[str_[left]] -= 1 if freq[str_[left]] == 0: del freq[str_[left]] left += 1 right += 1 return answer
python
15
0.607843
58
23.285714
21
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
class Solution: def findSubString(self, a): dict = {} n = len(set(a)) left = 0 right = 0 ans = len(a) while right < len(a): if a[right] not in dict: dict[a[right]] = 1 else: dict[a[right]] += 1 if len(dict) == n: while dict[a[left]] > 1: dict[a[left]] -= 1 left += 1 ans = min(ans, right - left + 1) right += 1 return ans
python
15
0.518617
36
17.8
20
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
import math class Solution: def findSubString(self, s): dicti = {} mini = math.inf k = len(set(s)) n = len(s) (i, j) = (0, 0) while j < n: if s[j] not in dicti: dicti[s[j]] = 1 else: dicti[s[j]] += 1 if len(dicti) < k: j += 1 elif len(dicti) == k: while len(dicti) == k: mini = min(mini, j - i + 1) if s[i] in dicti: dicti[s[i]] -= 1 if dicti[s[i]] == 0: del dicti[s[i]] i += 1 j += 1 return mini
python
19
0.46875
32
16.777778
27
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
from collections import defaultdict class Solution: def findSubString(self, arr): dic = defaultdict(lambda : 0) i = 0 j = 0 n = len(set(arr)) ans = len(arr) while j < len(arr): dic[arr[j]] += 1 if len(dic) < n: j += 1 if len(dic) == n: while dic[arr[i]] > 1: dic[arr[i]] -= 1 i += 1 ans = min(ans, j - i + 1) j += 1 return ans
python
15
0.522427
35
17.047619
21
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
class Solution: def findSubString(self, str): d = {} for i in str: d[i] = 0 i = 0 j = 0 ans = len(str) count = len(d) temp = 0 while j < len(str): while temp < count and j < len(str): if d[str[j]] == 0: temp += 1 d[str[j]] += 1 j += 1 while temp >= count: d[str[i]] -= 1 if d[str[i]] == 0: temp -= 1 i += 1 ans = min(ans, j - i + 1) return ans
python
13
0.460976
39
16.083333
24
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
from collections import deque class Solution: def findSubString(self, stre): s = set(stre) set_len = len(s) j = 0 minlen = 1000000000.0 mp = {} n = len(stre) for i in range(n): if stre[i] not in mp: mp[stre[i]] = 1 else: mp[stre[i]] += 1 while j <= i and len(mp) == set_len: if minlen > i - j + 1: minlen = i - j + 1 mp[stre[j]] -= 1 if mp[stre[j]] == 0: del mp[stre[j]] j += 1 return minlen
python
15
0.526432
39
17.916667
24
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
class Solution: def findSubString(self, str): m = {} n = len(set(str)) length = float('inf') j = 0 for i in range(len(str)): m[str[i]] = m.get(str[i], 0) + 1 if len(m) == n: while m[str[j]] > 1: m[str[j]] -= 1 j += 1 length = min(length, i - j + 1) return length
python
15
0.501661
35
19.066667
15
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
class Solution: def findSubString(self, str): dict = {} ans = 1000000000.0 for i in str: if i not in dict: dict[i] = 1 dict2 = {} j = 0 for i in range(len(str)): if str[i] not in dict2: dict2[str[i]] = 1 else: dict2[str[i]] += 1 while len(dict) == len(dict2): ans = min(ans, i - j + 1) if dict2[str[j]] > 1: dict2[str[j]] -= 1 elif dict2[str[j]] == 1: dict2.pop(str[j]) j += 1 return ans
python
16
0.519824
33
18.73913
23
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
from collections import defaultdict class Solution: def findSubString(self, s): a = set(s) i = 0 t = {} min_len = float('inf') for j in range(len(s)): if s[j] not in t: t[s[j]] = 0 t[s[j]] += 1 while len(t) == len(a): min_len = min(min_len, j - i + 1) t[s[i]] -= 1 if t[s[i]] == 0: del t[s[i]] i += 1 return min_len
python
15
0.49863
37
17.25
20
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
class Solution: def findSubString(self, str): from collections import defaultdict curr_count = defaultdict(lambda : 0) dist_count = len(set([x for x in str])) if len(str) <= 1: return 1 counter = 0 start = 0 min_len = len(str) for i in range(len(str)): curr_count[str[i]] += 1 if curr_count[str[i]] == 1: counter += 1 if counter == dist_count: while curr_count[str[start]] > 1: if curr_count[str[start]] > 1: curr_count[str[start]] -= 1 start += 1 window_len = i - start + 1 if window_len < min_len: min_len = window_len start_index = start a = min_len return a
python
17
0.594044
41
23.538462
26
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
class Solution: def findSubString(self, str): d = {} for i in str: if i not in d: d[i] = 0 (i, j) = (0, float('inf')) (count, out) = (0, float('inf')) for j in range(len(str)): if d[str[j]] == 0: count += 1 d[str[j]] += 1 if count == len(d): while i < j: d[str[i]] -= 1 if d[str[i]] == 0: out = min(out, j - i + 1) count -= 1 i += 1 break i += 1 return out if out != float('inf') else 1
python
19
0.450431
42
19.173913
23
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
class Solution: def findSubString(self, str): k = len(set(str)) memo = {} ans = len(str) (i, j) = (0, 0) while j < len(str): memo[str[j]] = memo.get(str[j], 0) + 1 if len(memo) < k: j += 1 elif len(memo) == k: while len(memo) == k: memo[str[i]] -= 1 if memo[str[i]] == 0: del memo[str[i]] i += 1 ans = min(ans, j - i + 2) j += 1 elif len(memo) > k: while len(memo) > k: memo[str[i]] -= 1 if memo[str[i]] == 0: del memo[str[i]] i += 1 j += 1 return ans
python
17
0.457721
41
19.148148
27
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
class Solution: def findSubString(self, str): res = 100000 d = {} for i in range(len(str)): if str[i] not in d: d[str[i]] = 0 s1 = set() count = len(d) l = 0 for i in range(len(str)): s1.add(str[i]) d[str[i]] = d[str[i]] + 1 while count == len(s1) and d[str[l]] != 0: d[str[l]] = d[str[l]] - 1 if d[str[l]] == 0: s1.remove(str[l]) res = min(res, i - l + 1) l = l + 1 return res
python
17
0.490783
45
19.666667
21
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
class Solution: def findSubString(self, str): ans = len(str) N = len(str) n = len(set(str)) (i, j) = (0, 0) d = {} while i < N: if str[i] not in d: d[str[i]] = 1 else: d[str[i]] += 1 if len(d) == n: while d[str[j]] > 1: d[str[j]] -= 1 j += 1 ans = min(ans, i - j + 1) i += 1 return ans
python
15
0.444118
30
16
20
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
class Solution: def findSubString(self, s): freq = {} for c in s: freq[c] = 0 unique_chars = len(freq) left = 0 right = 0 count = 0 min_length = float('inf') while right < len(s): if s[right] in freq: freq[s[right]] += 1 if freq[s[right]] == 1: count += 1 right += 1 while count == unique_chars: if right - left < min_length: min_length = right - left if s[left] in freq: freq[s[left]] -= 1 if freq[s[left]] == 0: count -= 1 left += 1 return min_length
python
15
0.54049
33
19.423077
26
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
class Solution: def findSubString(self, str): d = {} for i in str: if i not in d: d[i] = 0 x = len(d) ans = 999999 i = 0 j = 0 c = 0 while i < len(str): if d[str[i]] == 0: c += 1 d[str[i]] += 1 if c == x: f = True while c == x: ans = min(ans, i - j + 1) d[str[j]] -= 1 if d[str[j]] == 0: c -= 1 j += 1 i += 1 return ans
python
17
0.410579
30
14.269231
26
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
class Solution: def findSubString(self, str): reslen = len(str) s = set() d = dict() for i in range(len(str)): s.add(str[i]) i = 0 count = 0 for j in range(len(str)): d[str[j]] = d.get(str[j], 0) + 1 if d[str[j]] == 1: count += 1 if count == len(s): while d[str[i]] > 1: if d[str[i]] > 1: d[str[i]] -= 1 i += 1 if reslen > j - i + 1: reslen = j - i + 1 return reslen
python
17
0.47907
35
18.545455
22
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
from collections import defaultdict class Solution: def findSubString(self, strr): n = len(strr) dist_count = len(set([x for x in strr])) if n == dist_count: return n curr_count = dict() count = 0 start = 0 min_len = n for i in range(n): curr_count[strr[i]] = curr_count.get(strr[i], 0) + 1 if curr_count[strr[i]] == 1: count += 1 if count == dist_count: while curr_count[strr[start]] > 1: if curr_count[strr[start]] > 1: curr_count[strr[start]] -= 1 start += 1 if min_len > i - start + 1: min_len = i - start + 1 return min_len
python
17
0.584874
55
22.8
25
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
class Solution: def findSubString(self, s): n = len(s) res = n i = 0 uniq = set(list(s)) found = {} for j in range(n): if s[j] in found: found[s[j]] += 1 else: found[s[j]] = 1 while i < j: if found[s[i]] > 1: found[s[i]] -= 1 i += 1 else: break if len(found) == len(uniq): res = min(res, j - i + 1) return res
python
15
0.479893
30
15.954545
22
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
from collections import defaultdict class Solution: def findSubString(self, s): n = len(s) if n <= 1: return len(s) dis_char = len(set(list(s))) curr = defaultdict(lambda : 0) cnt = 0 minlen = n start = 0 for j in range(n): curr[s[j]] += 1 if curr[s[j]] == 1: cnt += 1 if cnt == dis_char: while curr[s[start]] > 1: curr[s[start]] -= 1 start += 1 length = j - start + 1 if length < minlen: minlen = length startind = start return minlen
python
15
0.560396
35
18.423077
26
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
class Solution: def findSubString(self, S): distinct_chars = set(S) n = len(S) left = 0 min_length = n count = [0] * 256 distinct = 0 for right in range(n): count[ord(S[right])] += 1 if count[ord(S[right])] == 1: distinct += 1 if distinct == len(distinct_chars): while count[ord(S[left])] > 1: count[ord(S[left])] -= 1 left += 1 min_length = min(min_length, right - left + 1) count[ord(S[left])] -= 1 left += 1 distinct -= 1 return min_length
python
17
0.563492
50
21.909091
22
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
class Solution: def findSubString(self, str): maxi = len(str) sets = set(str) i = 0 j = 0 m = {} while i < len(str): m[str[i]] = 1 + m.get(str[i], 0) if len(m) >= len(sets): while m[str[j]] > 1: m[str[j]] -= 1 j += 1 maxi = min(maxi, i - j + 1) i += 1 return maxi
python
15
0.47557
35
17.058824
17
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
class Solution: def findSubString(self, input_string): start = 0 end = 1 alphabet_dict = {} distinct_list = list(set(input_string)) for i in range(0, len(distinct_list)): alphabet_dict[distinct_list[i]] = 0 n = len(distinct_list) count = 1 alphabet_dict[input_string[0]] = 1 answer = len(input_string) while start <= end < len(input_string): if count < n: element = input_string[end] if alphabet_dict[element] == 0: alphabet_dict[element] = 1 count = count + 1 else: alphabet_dict[element] = alphabet_dict[element] + 1 end = end + 1 elif count == n: answer = min(answer, end - start) element = input_string[start] if element in alphabet_dict and alphabet_dict[element] == 1: count = count - 1 alphabet_dict[element] = alphabet_dict[element] - 1 start = start + 1 while count == n: answer = min(answer, end - start) element = input_string[start] if element in alphabet_dict and alphabet_dict[element] == 1: count = count - 1 alphabet_dict[element] = alphabet_dict[element] - 1 start = start + 1 return answer
python
16
0.63864
64
29.216216
37
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
from collections import Counter class Solution: def findSubString(self, str): dic1 = Counter(str) dic2 = dict() (i, j) = (0, 0) res = 10000000000 while j < len(str): if str[j] in dic2: dic2[str[j]] += 1 else: dic2[str[j]] = 1 if len(dic1) == len(dic2): while len(dic1) == len(dic2): res = min(res, j - i + 1) dic2[str[i]] -= 1 if dic2[str[i]] == 0: del dic2[str[i]] i += 1 j += 1 return res
python
17
0.528509
33
18.826087
23
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
import math class Solution: def findSubString(self, s): freq = {} for c in s: freq[c] = 0 (b, d, ans) = (0, 0, math.inf) for (i, c) in enumerate(s): while d == len(freq.keys()): freq[s[b]] -= 1 if freq[s[b]] == 0: ans = min(ans, i - b) d -= 1 b += 1 freq[c] += 1 if freq[c] == 1: d += 1 while d == len(freq.keys()): freq[s[b]] -= 1 if freq[s[b]] == 0: ans = min(ans, i - b + 1) d -= 1 b += 1 return ans
python
16
0.452431
32
17.192308
26
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
class Solution: def findSubString(self, str): n = len(str) ans = 0 length = n s = list(set(str)) d = dict() count = 0 start = 0 for i in range(n): if str[i] not in d.keys(): d[str[i]] = 1 count += 1 else: d[str[i]] += 1 if count == len(s): while d[str[start]] > 1: d[str[start]] -= 1 start += 1 ans = i - start + 1 if length > ans: length = ans return length
python
15
0.505855
30
16.791667
24
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
from collections import defaultdict class Solution: def findSubString(self, s): control = set(s) m = len(control) n = len(s) test = defaultdict(lambda : 0) mini = float('inf') i = 0 for j in range(n): while len(test) < m and i < n: test[s[i]] += 1 i += 1 if len(test) < m: break mini = min(mini, i - j) test[s[j]] -= 1 if test[s[j]] == 0: del test[s[j]] return mini
python
13
0.555288
35
17.909091
22
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco
class Solution: def findSubString(self, str): i = 0 j = 0 s = len(set(str)) n = len(str) ans = n dic = {} while i < n: if str[i] not in dic: dic[str[i]] = 1 else: dic[str[i]] += 1 if len(dic) == s: while dic[str[j]] > 1: dic[str[j]] -= 1 j += 1 ans = min(ans, i - j + 1) i += 1 return ans
python
15
0.463768
30
15.428571
21
Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: Input : "AABBBCBBAC" Output : 3 Explanation : Sub-string -> "BAC" Example 2: Input : "aaab" Output : 2 Explanation : Sub-string -> "ab" Example 3: Input : "GEEKSGEEKSFOR" Output : 8 Explanation : Sub-string -> "GEEKSFOR" Your Task: You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string. Expected Time Complexity: O(256.N) Expected Auxiliary Space: O(256) Constraints: 1 ≀ |S| ≀ 10^{5} String may contain both type of English Alphabets.
taco