
15 Coding Interview Questions I've Been Asked at Top Tech Companies
After interviewing at multiple tech companies, these are the questions that came up most often — with clean solutions and explanations. 1. Two Sum The classic warm-up: def two_sum ( nums : list [ int ], target : int ) -> list [ int ]: seen = {} for i , num in enumerate ( nums ): complement = target - num if complement in seen : return [ seen [ complement ], i ] seen [ num ] = i return [] # Time: O(n), Space: O(n) assert two_sum ([ 2 , 7 , 11 , 15 ], 9 ) == [ 0 , 1 ] 2. Valid Parentheses def is_valid ( s : str ) -> bool : stack = [] pairs = { ' ) ' : ' ( ' , ' ] ' : ' [ ' , ' } ' : ' { ' } for char in s : if char in ' ([{ ' : stack . append ( char ) elif char in pairs : if not stack or stack [ - 1 ] != pairs [ char ]: return False stack . pop () return len ( stack ) == 0 assert is_valid ( " ({[]}) " ) == True assert is_valid ( " ([)] " ) == False 3. Merge Two Sorted Lists class ListNode : def __init__ ( self , val = 0 , next = None ): self . val = val self . next = next def merge_two_li
Continue reading on Dev.to Tutorial
Opens in a new tab


