

Suppose given number is ‘13’ so we return ‘3’ as the answer as we can write 13 = 3 ^ 2 + 3 ^ 1 + 3 ^ 0. '3' is the smallest number 'B for which 13 base 'B' is ‘1 1 1’. So, the 'NINJA BASE' of 'N' = 13 is 3.
You are not required to print anything explicitly. It has already been taken care of. Just implement the function.
The first line of input contains a ‘T’ number of test cases.
The first line of each test case contains an integer ‘N’ denoting the given number.
For each test case, return the smallest ‘NINJA BASE’.
1 <= T <= 10 ^ 4
3 <= N <= 10 ^ 6
Time Limit: 1 second
Can you do this in O(logN) time and constant space?
The idea here is starting from the smallest number i.e. ‘2’, we traverse up to the given number. Starting from ‘2’, we check if we can write the number ‘N’ in form of base ‘i’. If so, we say that the number ‘i’ is ‘NINJA BASE’ else we increase its value.
The idea here is to use binary search as according to our constraints number can be up to 10 ^ 6 so the maximum length of the representation possible is up to ‘17’. So in every step of binary search, we can say if the power of mid raised to the max is smaller than the number, we have to increase our start else we can decrease our end where start represents ‘2’ as the smallest base possible is ‘2’. We say ‘N - 1’ is our end as the largest base possible is ‘N - 1’.
First Digit One
Special Digit Numbers
Minimize Maximum Adjacent Distance
Sorted Doubly Linked List to Balanced BST
Minimized Maximum of Products Distributed to Any Store