Ctrl K

Digit Sum in Another Base

Easy
You are given a decimal integer number and a base base. Write number in base base, then add up the digits of that representation as ordinary decimal values. Return the sum.
Example 1
number=29, base=4 → 5

29 written in base 4 is 131, and 1 + 3 + 1 = 5.

Example 2
number=15, base=2 → 4

15 in binary is 1111; four ones give 4.

Example 3
number=81, base=9 → 1

81 in base 9 is 100, whose digits add up to 1.

Constraints
  • 1 ≤ number ≤ 100
  • 2 ≤ base ≤ 10
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsA Number That Reads Both Ways EasyValue of a Roman Numeral EasyAdd One to a Digit Array EasySum of Binary Strings EasyWhole Square Root Easy
loading Python…
Input
number=29, base=4
Expected
5

Run checks the first 3 tests in your browser. Submit checks all 90 tests on the server, hidden ones included.