WA in Binary Concatenation(BINFUN)

Hi, Tried to solve it partial points. Could anyone suggests test case for BINFUN
Question: CodeChef: Practical coding for everyone
My solution: CodeChef: Practical coding for everyone
Any help is appreciated.

i and j both start from zero.

1 Like

first mistake is that you are taking a[i],a[j] such that i<j…you should also consider cases in which i>j
second mistake binXplusY - binYplusX can be negative also so you cannot assign unsigned type to your variables binXplusY ,binYplusX as they will give wrong values when answer is negative.
Rectify these two mistakes and you are good to go…you will get partial marks

1 Like

Thanks a lot, it worked

Why can’t we take i==j case too, then the worst case maximum value is 0. Question says ‘over all valid i and j’. Are we to assume valid i and j means i and j are unequal?

i==j case will give diff 0, that is minimum I can get
since string concat will be same both ways.

It is not clearly mentioned in the ques that whether i can be equal to j but i’m pretty much sure that you will get a positive answer from other cases(i>j or i<j) since one of the two (binXplusY -binYplusX) and (binYplusX -binXplusY) will be positive anyway if the two numbers are not equal.So even if you take i==j case also then,answer will not get affected.

1 Like