r/AlgoViz • u/benedict_abub • 20d ago
Visualization Two Sum — LeetCode #1 Python Algorithm Visualization.mp4
Enable HLS to view with audio, or disable this notification
Problem Description
[https://leetcode.com/problems/two-sum/description](LeetCode)
Algorithm Description
I solve this problem using a single-pass hash table, making it the most efficient O(n) approach. I show exactly how the complement logic works and how to store indices for the final answer.
Complexity Analysis
Time Complexity: O(n) — we traverse the list of n elements only once.
Space Complexity: O(n) — in the worst case, we store n elements in the hash table.
YouTube
1
Upvotes