Ctrl K

Counting in Sevens

Easy
A tribe on a remote island counts using only seven digits, 0 through 6, and each place is worth 7 times the place to its right. You are given an integer value. Return a string with its base 7 representation. Negative numbers get a leading -, and there must be no leading zeros (zero itself is written as "0").
Example 1
value=60 → '114'

60 = 1·49 + 1·7 + 4, so in base seven it is 114.

Example 2
value=-14 → '-20'

14 = 2·7 + 0, which is 20; the minus sign stays in front.

Example 3
value=6 → '6'

Numbers below 7 take a single digit, same as in decimal.

Constraints
  • -10⁷ ≤ value ≤ 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
value=60
Expected
'114'

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