Ninja and Binary String Problem Statement

Ninja has a binary string S of size N given by his friend. The task is to determine if it's possible to sort the binary string S in decreasing order by removing any number of non-adjacent characters. Your help is needed to solve this challenge.

Input:

int T  // number of test cases
int N // size of the binary string for each test case
string S // the binary string

Output:

Print "true" for each test case if the string can be sorted in decreasing order, otherwise "false".

Example:

Input:
2
5
10101
3
110
Output:
true
true

Constraints:

  • 1 <= T <= 5
  • 1 <= N <= 10^4
  • Where T is the total number of test cases and N is the size of the given string.
  • Time limit: 1 sec

Note:

  • You do not need to input or print anything, as it has already been taken care of. Just implement the given function.
  • A binary string is a string which contains only '1' or '0' characters.
  • The order is not strictly decreasing.
AnswerBot
2d

Determine if a binary string can be sorted in decreasing order by removing non-adjacent characters.

  • Check if the count of '1's in the string is equal to the length of the string, as it can be sorted in...read more

Help your peers!
Add answer anonymously...
Amazon Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter