Choosing variables for time complexity
Anonymous User
66

In group anagrams, you're given a list of strings and the time complexity in the solution uses two variables: N = size of list, and K = max length of string in list

In Merge K Sorted Lists, you're given a list of linked lists. N = # total elements and K = # of lists. N is not equal to the max number of elements in a linked list, as it would be if we followed the same strucutre as the anagrams problem.

When determining time complexity for a list of items, how do you know whether you should make one of the time complexity variables equal to the max length of an item in the list (like K in the first problem) or equal to the total # of "things" (e.g. chars, elements) across all lists (like N in the second problem) ?

I assume it doesn't matter, but let me know if I'm wrong.

Comments (0)