Chef and digits of a number
All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef has a number D containing only digits 0's and 1's. He wants to make the number to have all the digits same. For that, he will change exactly one digit, i.e. from 0 to 1 or from 1 to 0. If it is possible to make all digits equal (either all 0's or all 1's) by flipping exactly 1 digit then output "Yes", else print "No" (quotes for clarity)
The first line will contain an integer T representing the number of test cases.
Each test case contain a number made of only digits 1's and 0's on newline
Print T lines with a "Yes" or a "No", depending on whether its possible to make it all 0s or 1s or not.
ConstraintsSubtask #1: (40 points)
- 1 ≤ T ≤ 50
- 1 ≤ Length of the number D ≤ 50
- 1 ≤ T ≤ 10
- 1 ≤ Length of the number D ≤ 105
Input: 2 101 11 Output: Yes No
Example case 1. In 101, the 0 can be flipped to make it all 1..
Example case 2. No matter whichever digit you flip, you will not get the desired string.
|Tags||ad-hoc, cakewalk, chandubaba, sept16, string|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.