737. Convert Binary to Octal

You are given a binary number N in the form of a string. Your task is to convert the binary number to its equivalent octal (base-8) representation and return it as a string.

Example 1:

Input: N = "1100110"

Output: "146"

Explanation: Binary 1100110 = Octal 146

Example 2:

Input: N = "11111"

Output: "37"

Explanation: Binary 11111 = Decimal 31 = Octal 37

Now Your Turn!

Pick the correct output for the given input

Input: N = "100000"

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= N.length <= 30
  • N consists only of '0' and '1' characters
0
class Solution {
public:
string binaryToOctal(string N) {
// Your code goes here
}
};
 
Test Case

Input:

N