Refactored new solution #6 to only use 1 loop, remove dups and keep solution at O(n) time complexity.