Solutions are presented as using the least memory and the fastest execution time. It also takes the top
10 most recent solutions from each language. If you want to limit to a specific index, click the
"Solved" button and go to that problem.
Problems
B'You are given a string s , consisting of n letters, each letter is either 'a ' or 'b '. The letters in the string are numbered from 1 to n . s[l; r] is a continuous substring of letters from index l to r of the string inclusive. A string is called balanced if the number of letters 'a ' in it is equal to the number of letters 'b '. For example, strings "baba" and "aabbab" are balanced and strings "aaab" and "b" are not. Find any non-empty balanced substring s[l; r] of string s . Print its l and r ( 1 <= l <= r <= n ). If there is no such substring, then print -1 -1 . The first line contains a single integer t ( 1 <= t <= 1000 ) -- the number of testcases. Then the descriptions of t testcases follow. The first line of the testcase contains a single integer n ( 1 <= n <= 50 ) -- the length of the string. The second line of the testcase contains a string s , consisting of n letters, each letter is either 'a ' or 'b '. For each testcase print two integers. If there exists a non-empty balanced substring s[l; r] , then print l r ( 1 <= l <= r <= n ). Otherwise, print -1 -1 . In the first testcase there are no non-empty balanced subtrings. In the second and third testcases there are multiple balanced substrings, including the entire string "abbaba" and substring "baba". '... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
128295101 |
Abdullmenem_Ramadan1 |
A |
Sept. 8, 2021, 8:05 p.m. |
OK |
GNU C++14 |
TESTS |
3 |
0 |
0 |
|
|
128290625 |
_mayushi_ |
A |
Sept. 8, 2021, 6:38 p.m. |
OK |
GNU C++14 |
TESTS |
3 |
0 |
0 |
|
|
128284113 |
mehtaabhinav567 |
A |
Sept. 8, 2021, 5:11 p.m. |
OK |
GNU C++14 |
TESTS |
3 |
0 |
0 |
|
|
128283788 |
155016 |
A |
Sept. 8, 2021, 5:07 p.m. |
OK |
GNU C++14 |
TESTS |
3 |
0 |
0 |
|
|
128280388 |
Akshat_25 |
A |
Sept. 8, 2021, 4:41 p.m. |
OK |
GNU C++14 |
TESTS |
3 |
0 |
0 |
|
|
128316109 |
VitConXuSoTiHon |
A |
Sept. 9, 2021, 6:01 a.m. |
OK |
GNU C++14 |
TESTS |
3 |
0 |
3686400 |
|
|
128302754 |
liamaking |
A |
Sept. 9, 2021, 12:42 a.m. |
OK |
GNU C++14 |
TESTS |
3 |
0 |
3686400 |
|
|
128302366 |
Spectre_07 |
A |
Sept. 9, 2021, 12:29 a.m. |
OK |
GNU C++14 |
TESTS |
3 |
0 |
3686400 |
|
|
128293608 |
NITIN_K_SHUKLA |
A |
Sept. 8, 2021, 7:33 p.m. |
OK |
GNU C++14 |
TESTS |
3 |
0 |
3686400 |
|
|
128308909 |
fk_multi |
A |
Sept. 9, 2021, 3:43 a.m. |
OK |
GNU C++14 |
TESTS |
3 |
0 |
3788800 |
|
|
remove filters
Back to search problems