All problems
0671EasyMathString

Seven-Rod Counting Frame

Tracked in this browser only
Write code

Trains the technique from

LeetCode 504Base 7

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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