Time & Space Complexity

I have solved this question with 100% accuracy, but I am not able to calculate the Time Complexity & Space Complexity of my solution.

Can you please explain the Time & Space Complexity of my solution?

My Solution -> https://ide.codingblocks.com/s/574986

Time complexity to make substring is O(n^2) then to check weather the substring is already visited or not we are doing n operations also to check if it’s a cb number or not we are doing 10 operations. Overall complexity as per your code i feel is O(10*n^3) ~ O(n^3).

What will be the Space Complexity?? Please explain it!!

You are creating all subsets of a string, and then iterating on them. So there will be 2^n subsets.


But not all subsets will be of equal length. So can’t label a fix space complexity.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.