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
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, in which case it can b...read more

Help your peers!
Select
Add answer anonymously...

Arcesium Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. 1) Maximum meetings in one room 2)Bottom view of tree 3) Serialize deserialize b...read more
A Software Developer Intern was asked Q. Number of Islands Problem Statement You are given a non-empty grid that consists...read more
A Software Developer Intern was asked Q. N-th Node From The End Problem Statement You are provided with a Singly Linked L...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. 1) Maximum meetings in one room 2)Bottom view of tree 3) Serialize deserialize b...read more
A Software Developer Intern was asked Q2. Number of Islands Problem Statement You are given a non-empty grid that consists...read more
A Software Developer Intern was asked Q3. N-th Node From The End Problem Statement You are provided with a Singly Linked L...read more
Arcesium Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits