KAN15RTI - Editorial

PROBLEM LINK:

Practice
Contest

Editorialist: Karan Aggarwal

DIFFICULTY:

EASY

PREREQUISITES:

Addition in Binary Representation.

PROBLEM:

Given a binary string L of length N, (N<=1000), and a integer K, (K<=1e18), output the binary string formed after adding K to L.

EXPLANATION:

Modify string L, from least significant bit to most significant bit position to add K to it.
Also, if there is carry, we might have to increase the string length. But it wont happen more than 60 times. Also, if N is small, we can actually convert L into long long and add K, and the print back its binary.

Complexity : O(N) per test case.

//