krandor305's blog

By krandor305, history, 7 weeks ago, In English

Hello everyone can someone explain this to me:

In this problem

I have to construct a palindrome with limited 0 and 1s

The problem doesn't state that if we have remaining a or b (remaining 0 or 1 to add) the solution must return -1

and also in the image I sent,there is one case(1) that allow a or b to be remaining (a>0 or b>0) in the end

My main queston is:How in the sixth case we should return -1 contrarly to the seventh case?

  • Vote: I like it
  • -20
  • Vote: I do not like it

7 weeks ago, # |
  Vote: I like it +8 Vote: I do not like it

Hi, Krandor.
This problem tells you that string s is of length a+b, which means that you must construct the string using a '0' and b '1'.
in the 6-th example, you have 0 '0' and 1 '1',so you can only construct '1', but the string s is '0', so the answer is -1.
in the 7-th example, you have 3 '1', so you can construct '111'.
Please read the question carefully before asking :-)

  • »
    7 weeks ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    aah I see, so it is not only dependant to the number of question marks Thank you very much