Coding Challenge Solutions
A minimalist space dedicated to breaking down complex data structures and competitive programming problems. High performance explanations for low-level thinking.
Recent solutions
#1Two Sum
EasyUse a hash map to store complements as you iterate, achieving O(n) time instead of the brute-force O(n²) nested loop approach.
#20Valid Parentheses
EasyPush opening brackets onto a stack and pop when a matching closing bracket is found. If the stack is empty at the end, the string is valid.
#21Merge Two Sorted Lists
EasyCompare heads of both lists and recursively (or iteratively) attach the smaller node, building the merged list in sorted order.
#94Binary Tree Inorder Traversal
EasyTraverse left subtree, visit the node, then traverse right. Can be done recursively or iteratively with an explicit stack.
#121Best Time to Buy and Sell Stock
EasyTrack the minimum price seen so far and compute the max profit at each step. A single pass gives O(n) time and O(1) space.
#141Linked List Cycle
EasyUse Floyd's tortoise and hare algorithm — a slow and fast pointer. If they meet, there's a cycle; if fast reaches null, there isn't.