748. Convert Octal to Binary

You are given a number in Octal (base 8) format as a string. Your task is to convert it into its Binary (base 2) representation and return it as a string.

Each octal digit should be converted into its corresponding 3-bit binary representation. The final binary string must be the concatenation of these binary blocks for all octal digits in order.

Example 1:

Input: N = 345

Output: 011100101

Explanation: 3 -> 011, 4 -> 100, 5 -> 101 → final binary: 011100101

Example 2:

Input: N = 170

Output: 001111000

Explanation: 1 -> 001, 7 -> 111, 0 -> 000 → final binary: 001111000

Now Your Turn!

Pick the correct output for the given input

Input: N = 765

Still unsure what the problem is asking ?

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

Constraints:

  • The input will only contain digits from 0 to 7.
  • 1 <= length of Octal number <= 1000
  • Output must contain leading zeros if any digit’s binary representation has them (e.g., 7 → 111, 2 → 010)
0
class Solution {
public:
string octalToBinary(string N) {
// Your code goes here
}
};
Test Case

Input:

N