Set 2- Common 20 Interview questions and ans. Data Structures and Algorithms (DSA) with explanations and code
--- 1. Two Sum (Array + Hashing) Problem: Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. def two_sum(nums, target): hashmap = {} for i, num in enumerate(nums): complement = target - num if complement in hashmap: return [hashmap[complement], i] hashmap[num] = i Explanation: We use a hash map to store numbers we've seen and their indices. For each element num, we compute target - num (called complement). If complement is already in the hash map, we found the answer. Time complexity: O(n), Space: O(n) 2. Reverse a Linked List (Linked List) Problem: Reverse a singly linked list. class ListNode: def __init__(self, val): self.val = val self.next = None def reverse_list(head): prev = No...