Problem statement

https://leetcode.com/problems/encode-number/

Solution

Just horrible problem: you should deduce from the following table, this is just absolutely lazy way to create problem. Even though I solved it in like 1 minute, it should not be allowed on coding interview. We can guess that what we have is binary representation of num + 1 with removed first symbol.

Complexity

Time and space complexity is len(num).

Code

class Solution:
    def encode(self, num):
        return bin(num + 1)[3:]