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 andN
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
4mo
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 & answers
A Software Developer was asked 1mo agoQ. Could you describe the process for designing a data structure that allows for al...read more
A Software Developer was asked 1mo agoQ. What is HTML?
A Software Developer was asked 1mo agoQ. What is MySQL?
Popular interview questions of Software Developer
A Software Developer was asked 1mo agoQ1. Could you describe the process for designing a data structure that allows for al...read more
A Software Developer was asked 1mo agoQ2. What is MySQL?
A Software Developer was asked 1mo agoQ3. What is Java?
Top HR questions asked in Amazon Software Developer
A Software Developer was asked 1mo agoQ1. Tell me about a time you had to get to the root cause of a problem
A Software Developer was asked 5mo agoQ2. What are the short-term and long-term goals for the team or organization?
A Software Developer was asked 5mo agoQ3. Why do you want to work at Amazon?
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

