- Time : O(n len(s) n * n)
Space : O(n)
compare two string with length diff is 1 will take
len(s) * n * n
in worst case.- worst case is there are only two group of string [len(s), len(s) - 1] and number of two groups’s difference is at most one.
- In this case, time complexity will make
O(len(s) * (n / 2) * (n / 2))
- Length of TC distribution is wide, time complexity will converge to
O(n * len(s) * n)
1 | bool adj(string& origin, string& target) { |
- Time : O(n len(s) len(s))
Space : O(n)
making smaller string will take
len(s) * len(s)
1 |
|