thecodingcompany
DSA Pattern

Arrays & Hashing

The foundation pattern. Most interview suites open here.

Problems5
FocusPattern + approach

5 problems

Attempt each problem before reading the approach. In the interview, state the pattern and complexity out loud first — that is what earns the marks.

01Two SumEasyHashing
ProblemGiven an array and a target, return the indices of the two numbers that add to the target.
Approach. Store each value’s index in a hash map as you go. For each element, check whether target − element is already in the map. O(n) time, O(n) space.
02Maximum Subarray (Kadane’s Algorithm)MediumDynamic Programming
ProblemFind the contiguous subarray with the largest sum.
Approach. Track the best sum ending at the current index: current = max(value, current + value). Keep a running maximum. O(n) time, O(1) space.
03Product of Array Except SelfMediumPrefix Product
ProblemReturn an array where each element is the product of all others, without division.
Approach. Build a prefix-product pass and a suffix-product pass, multiplying them. O(n) time, O(1) extra space beyond the output.
04Contains DuplicateEasyHashing
ProblemReturn true if any value appears at least twice in the array.
Approach. Insert into a hash set; if the size does not grow, a duplicate exists. O(n) time.
05Longest Consecutive SequenceMediumHashing
ProblemFind the length of the longest run of consecutive integers, in O(n).
Approach. Put everything in a set, then start counting only from numbers whose predecessor is absent.

Practise here. Get placed there.

Prep+ is unlimited practice. When you are ready to turn it into an offer, TCC Placement Partner handles portfolio, resume and interviews.