Given 2 integers N and K. Convert N(given in Decimal) to base K.
 
Example 1:
Input:
N = 10, K = 2
Output:
1010
Explanation:
(10)_{10} = (1010)_{2}
Example 2:
Input:
N = 4, K = 8
Output:
4
Explanation:
(4)_{10} = (4)_{8}
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function changeBase() which takes Integers N and K as input and returns an integer as the answer.
 
Expected Time Complexity: O(log_{K}N)
Expected Auxiliary Space: O(log_{K}N)
 
Constraints:
1 <= N <= 10^{5}
2 <= K <= 10

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3

class Solution:
    def changeBase(self, N ,K):
        # code here 

Solutions:
class Solution:

	def changeBase(self, N: int, K: int) -> int:
		from collections import deque
		result = deque()
		while N:
			result.appendleft(str(N % K))
			N //= K
		return int(''.join(result))


class Solution:

	def changeBase(self, N, K):
		t = ''
		l = []
		while N != 0:
			l.append(N % K)
			N = N // K
		n = len(l)
		c = 0
		for i in range(n):
			l[i] += c
			if l[i] >= 10:
				l[i] = l[i] % 10
				c = 1
			else:
				c = 0
		if c == 1:
			l.append(1)
		for i in range(len(l) - 1, -1, -1):
			t += str(l[i])
		return t


class Solution:

	def changeBase(self, N, K):
		new = 0
		t = 1
		while N:
			new += N % K * t
			N = N // K
			t *= 10
		return new


class Solution:

	def changeBase(self, N, K):
		digit = 0
		m = 0
		tens = 1
		while N > 0:
			digit = N % K
			m = digit * tens + m
			N //= K
			tens = tens * 10
		return m