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
Yousef has given you a sequence (s) of length (n) consisting only of characters '(()' and '())'. You are allowed to perform the following operation at most once : Choose a substring(^{\text{∗}}) of (s) and remove it. Then, you may reinsert the removed characters back into the remaining string one by one. Each character can be placed at any arbitrary position, independently of the others. Yousef wants you to determine whether it is possible to obtain a regular bracket sequence(^{\text{†}}) after performing the operation at most once. (^{\text{∗}})A substring is a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it starts in position (3) and ends in position (6)), but "aa" or "d" aren't substrings of this string. So the substring of the string (s) from position (l) to position (r) is (sl, r= s_l s_{l+1} \dots s_r). (^{\text{†}})A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting the characters (1) and (+) between the original characters of the sequence. For example: bracket sequences (()()) and ((())) are regular (the resulting expressions are: ((1)+(1)) and (((1+1)+1))); bracket sequences ()(), (() and ()) are not. The first line contains an integer (t) ((1 \le t \le 10^4)) — the number of test cases. The descriptions of the test cases follow. The first line of each test case contains a single integer (n) ((1 \le n \le 2 \cdot 10^5)) — the length of the string (s). The second line of each test case contains a sequence (s) of length (n) consisting only of characters '(()' and '())'. It is guaranteed that the sum of (n) over all test cases does not exceed (2 \cdot 10^5). For each test case, output " YES " if the sequen |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|
373198656 |
akanksha |
B |
May 1, 2026, 5:46 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
3 |
15 |
0 |
|
|
|
373195562 |
ARIF_30 |
B |
May 1, 2026, 4:59 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
3 |
15 |
0 |
|
|
|
373194996 |
jaiswalXKrish |
B |
May 1, 2026, 4:49 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
3 |
15 |
0 |
|
|
|
373194822 |
Wbxsi5 |
B |
May 1, 2026, 4:47 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
3 |
15 |
0 |
|
|
|
373193027 |
Survivor45 |
B |
May 1, 2026, 4:13 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
3 |
15 |
0 |
|
|
|
373188209 |
tuananhluupham |
B |
May 1, 2026, 2:20 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
3 |
15 |
0 |
|
|
|
373187956 |
monesytop1 |
B |
May 1, 2026, 2:13 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
3 |
15 |
0 |
|
|
|
373184884 |
drjones |
B |
May 1, 2026, 12:14 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
3 |
15 |
0 |
|
|
|
373178823 |
imran67 |
B |
April 30, 2026, 9:05 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
3 |
15 |
0 |
|
|
|
373175677 |
devanshhhhhh |
B |
April 30, 2026, 8:05 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
3 |
15 |
0 |
|
|
remove filters
Back to search problems