Check if a Number is Binary
Determine if a given string of integers bin
represents a valid binary number. Return 'true'
if the string represents a valid binary number, otherwise return 'false'
. A binary number is strictly composed of the digits 0 and 1.
Input:
The first line contains an integer ‘T’ representing the number of test cases. Each of the next ‘T’ lines contains a single string ‘bin’.
Output:
For each test case, output a boolean: 'true' if the string is a valid binary number and 'false' otherwise. Each result should be printed on a separate line.
Example:
Input:
3
101
123
110110
Output:
true
false
true
Constraints:
1 <= T <= 50
1 <= length(bin) <= 10^4
Note:
No need to print anything; only implement the function to return the desired output.
Be the first one to answer
Add answer anonymously...
Top Oracle Mts1 interview questions & answers
Popular interview questions of Mts1
Stay ahead in your career. Get AmbitionBox app
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
Get AmbitionBox app