Back to all solutions

#1256 - Encode Number

Problem Description

Given a non-negative integer num, Return its encoding string.

The encoding is done by converting the integer to a string using a secret function that you should deduce from the following table:

Solution

/**
 * @param {number} num
 * @return {string}
 */
var encode = function(num) {
  return (num + 1).toString(2).slice(1);
};