Time complexity keypad issue

what is the time complexity of phone keypad solution implemented in the video.tell with some explanation

@Rj.25 hey, think about how many outputs there are, and how long it takes to compute an output.

If you have n characters, each of which maps to k options, then the number of possible results is k^n. The complexity of your algorithm is therefore at least k^n, or Omega(k^n), because O(k^n) outputs are enumerated.

We still need to consider how long it takes to compute each input. Notice that you’re building a String of length n by adding one character at a time. Since Strings are immutable, every time you add a character, an entirely new String must be created. The work involved to produce a String of length n by appending characters is 1 + 2 + … + n = O(n^2).
We can just multiply the number of results by the work for each result, to arrive at the final complexity O(n^2 * k^n), or more specifically, Theta(n^2 * k^n).
Hope you get it :slight_smile:

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.