Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6454 |

@blackshadows | 6380 |

@mb1973 | 5710 |

@Quandray | 5245 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 5046 |

@sanjay05 | 3762 |

@kirtidee18 | 3709 |

@mantu_singh | 3556 |

@marius_valentin_dragoi | 3523 |

@sushant_a | 3459 |

Complete Leaderboard | |

Handle | Score |

@cfwong8 | 1285 |

@gurshehzadsingh | 1052 |

@pritsahkar2000 | 812 |

@satyamchhatrala | 804 |

@nithinreddy3210 | 801 |

@iib2019024 | 745 |

@mohanreddy8847 | 704 |

@iamchaitanyahegde | 662 |

@shafeeq3543 | 647 |

@workit | 646 |

@AkashLahoty | 642 |

Complete Leaderboard |

Given binary string **str** of size **N** the task is to check if the given string is valid or not. A string is called valid if the number of **0's** equals the number of **1's** and at any moment starting from the left of the string number **0's** must be greater than or equals to the number of **1's**.

**Input: **

1. The first line of the input contains a single integer* * **T** denoting the number of test cases. The description of **T** test cases follows.

2. The first line of each test case contains a single integer** N****.**

3. The next line contains a binary string without spaces.

**Output:** For each test case, print** ****"yes"** if string is valid. Otherwise, print **"no"** (without quotes)

**Constraints:**

1. 1 <= T <= 100

2. 1 <= N <= 10^{4}

3. '0' <= str[i] <= '1'

**Example:
Input:**

2

4

0011

3

001

**Output:**

yes

no

**Explanation:**

**Test Case 1:** String has an equal number of ones and zeros and at each index(starting from left) the number of occurrences of **0's** is greater than or equals to the number of occurrences **1's**.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Valid String

...