Instead of looping through A, we always take the first element from hash table if it’s not empty. Since each element is removed from the hash table after checking, it is checked only once. Looping through A checks each element twice in the worse case scenario which all elements forms one range.
A small tweak for solution 13.12 in 1.4.7
It is really a good idea although it won’t improve the worst case time complexity but it definitely is a better code now since the extra checks are eliminated. Thanks Ray!
0 Likes