Evaluating Time & Space Complexity Of solutions

Hi Everyone,

I always find myself in a tough spot while evaluating the time and space complexity of my code during an interview or otherwise when I solve problems on Leetcode.
The complexities of order :

  1. n , n^2 are easiest to identiy.
  2. For logn, I rely on the fact that if I am using binary search then it is logn.
  3. For merge sort, I know it is nlogn. Again, If I use divide-and-conquer I know it is nlogn. But, I never undersood why? :P
  4. The most difficult which I always fail to identiy are: n! , 2^n , n^n.

Recently, in the monthly challange I solved the following two problems correctly, but I was not able to identify the space complexity:

  1. https://leetcode.com/problems/word-break/
    1.1) My TLE solution - solved 36/43 testcases - https://leetcode.com/submissions/detail/402590510/
    1.2) My Accepted solution - (Using caching to save results) - https://leetcode.com/submissions/detail/402942753/

  2. https://leetcode.com/problems/combination-sum/
    2.1) My Accpeted Solution1 - https://leetcode.com/submissions/detail/403473588/
    2.2) My Accepted Solution2 - https://leetcode.com/submissions/detail/403480124/
    Also, could not understand whether the above two solutions have different time comlexities.

It would be great if someone could share same useful information/links that could help me get better at understanding the time comlexities.

Cheers

Comments (2)