Base 7

EasyMathmath

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

Given an integer num, return its representation in base 7 as a string. Use no leading zeros; 0 is written as "0". Negative numbers are written with a leading - followed by the base-7 digits of their absolute value (for example -7 becomes "-10").

Examples

Input: num = 100
Output: "202"
100 = 2·49 + 0·7 + 2.
Input: num = -7
Output: "-10"
7 in base 7 is "10", with the sign in front.

Constraints

  • -10^7 <= num <= 10^7
  • No leading zeros in the output.
  • Negative results start with a single `-`.

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More math problems