ADDBIT - Editorial

PROBLEM LINK:

Practice

Contest

Author: Akshay Venkataramani

Tester: Timothy Jeyadoss

DIFFICULTY:

Cakewalk

PREREQUISITES:

Strings

EXPLANATION:

Simply traverse the string from left to right, and when you find a 0, break from the loop. Until then, keep adding to the answer.

This is the basic idea behind binary addition of 1 to any binary number(ofcourse, with the slight modification that if all bits are 1, append a extra 1 at the beginning).

This problem can be solved easily using “string” datatype that is available in C++, Java, Python etc. It is a little tedious to solve this problem in C, but simple nevertheless when you make note of the constraints properly.

TESTER’S SOLUTION:

Tester’s solution can be found here.