How to write code for input for this question

what shuld be base case in inputing the no.

@kailash_01
No need for base case here
When nodes are exhausted so will your tree