Increment
Easy Accuracy: 0.0% Submissions: 0 Points: 2

Given a base B and a number N in that base, increment the number by one and print the resulting number in that base only.
 

Example 1:

Input:
B = 2
N = 0010
Output:
11
Explanation:
(0010)2 = (2)10
2 + 1 = 3
(3)10 = (11)2

Example 2:

Input:
B = 13
N = 2139
Output:
231A
Explanation:
(2319)13 = (81)10
81 + 1 = 82
(82)10 = (231A)13


Your Task:
You don't need to read input or print anything. Your task is to complete the function inc() which takes an integer B, a string as input parameter and returns the string by incrementing the number by one in the same base.

 


Expected Time Complexity: O(log N)
Expected Space Complexity: O(1)

 

Constraints:
2 <= B <= 16
0000 <= N <= Max value in that base (e.g. 1111 for base 2, FFFF for base 16, etc.)

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.