Show problems as
Classic problem #504EasyMathString

Base 7

Real-world version: Seven-Rod Counting Frame
Tracked in this browser only
Read Base 7 on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A museum shows an old counting frame that works in sevens. Each rod carries from zero to six beads, and a rod is worth seven times the rod immediately to its right, so the rightmost rod counts ones, the next counts sevens, the next counts forty-nines, and so on.

Given an integer value, return the text a curator would write on the label: the bead count of each rod, read from the leftmost rod that carries a bead down to the ones rod, with no extra zero in front. If value is negative, put a single - before those digits. If value is zero, the label is the single character 0.

Examples

Example 1

Input
value = 342
Output
"666"

Six beads on the forty-nines rod, six on the sevens rod and six on the ones rod come to 294 plus 42 plus 6.

Example 2

Input
value = -48
Output
"-66"

Forty-eight is six sevens plus six ones, and the value is negative, so the label carries a leading minus.

Example 3

Input
value = 2401
Output
"10000"

2401 is seven multiplied by itself four times, so a single bead sits on the fifth rod from the right and every rod to its right is bare.

Constraints

  • -10^7 <= value <= 10^7

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def to_base_seven(value: int) -> str:
Java
public String toBaseSeven(int value)