Write an Integer Using Base Seven Digits

Quick Overview

Write an Integer Using Base Seven Digits. Return the base-seven string for num, using digits 0 through 6 and a leading minus sign only for negative values.

Write an Integer Using Base Seven Digits

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Return the base-seven string for num, using digits 0 through 6 and a leading minus sign only for negative values. Zero is represented by "0". ```cpp class Solution { public: string convertToBase7(int num); }; ``` ### Examples **Example 1:** ```text num = 50 Output: "101" Explanation: 50 = 1*49 + 0*7 + 1. ``` **Example 2:** ```text num = -15 Output: "-21" Explanation: 15 = 2*7 + 1. ``` ### Constraints - Input num ranges from -10000000 through 10000000, inclusive. ### Clarifying Questions Preserve the sign and ensure every output digit is in the base-seven alphabet. ```hint Read the boundary condition What does the remainder of division by seven tell you about the last digit? ``` ### Contract considerations Preserve the sign and ensure every output digit is in the base-seven alphabet.

Overview: Write an Integer Using Base Seven Digits. Return the base-seven string for num, using digits 0 through 6 and a leading minus sign only for negative values.

Google logo
Google
Source window: 0–6 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return the base-seven string for num, using digits 0 through 6 and a leading minus sign only for negative values. Zero is represented by "0".

class Solution {
public:
    string convertToBase7(int num);
};

Examples

Example 1:

num = 50
Output: "101"
Explanation: 50 = 1*49 + 0*7 + 1.

Example 2:

num = -15
Output: "-21"
Explanation: 15 = 2*7 + 1.

Constraints

  • Input num ranges from -10000000 through 10000000, inclusive.

Clarifying Questions Guidance

Preserve the sign and ensure every output digit is in the base-seven alphabet.

Contract considerations

Preserve the sign and ensure every output digit is in the base-seven alphabet.