×

 12 2 Rules for good string: 1) If at index i, the char is '1' and char at i-1 is '2', then char at i-2 should be '2'. 2) If at index i, the char is '2' and char at i-1 is '2', then char at i-2 should be '1'. Algorithm: 1) Traverse the two input strings and check for the above two conditions. 2) If the conditions doesn't satisfy at index i, swap the chars of both strings at i. 3) Again if the conflict occurs at the same index, the ans is 0. 4) If the conditions are satisfied at all indexes, the answer is a power of 2. Steps to calculate ans: 1) Count the no. of indexes at which the chars are same. Let this count be c. 2) There may be indexes at which the chars are not same. Count the pairs of such indexes. Let this count be p. 3) The ans is pow(2,c+p) Code: https://www.codechef.com/viewsolution/11855552 Time: 0.03 asked 18 Oct '16, 22:30 4★kay_kay 1.2k●7●21 accept rate: 20% 0★admin ♦♦ 19.8k●350●498●541 simple and clear explanation :-) (19 Oct '16, 13:35) i solved the same way 0.04 time ..nothing special about this question..just do what problem said. make good all work is done here.calculation is easy after anspection of a few test cases i guess. (20 Oct '16, 13:31)

 0 Can you explain why does it work? answered 20 Oct '16, 03:40 91●3 accept rate: 0%
 0 Amazing explanation. I've looked over so many answers but haven't found any matching this level of clarity. Good job ! answered 16 Jan '18, 23:11 10●1 accept rate: 0%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×968
×20

question asked: 18 Oct '16, 22:30

question was seen: 1,654 times

last updated: 16 Jan '18, 23:11