Loading section...

Classic Beginner Interview Problems

Concepts: pySubarraySumK, pyEquilibrium, pyPrefixHashMap

Two problems show up constantly in junior and mid-level data engineering screens: subarray sum equals K (count the subarrays), and equilibrium index (find the pivot where left sum equals right sum). Both are solved cleanly with prefix sums. The subarray sum problem has a brute-force O(n^2) solution that most candidates write first, and a prefix sum O(n) solution that differentiates them. The equilibrium index is almost embarrassingly simple with prefix sums but nearly impossible to solve elegantly without them. Let me walk you through both. Problem 1: Count Subarrays with Sum Equals K (LeetCode 560) Given an array of integers and a target K, count the number of contiguous subarrays whose elements sum to K. Brute force: try every pair (i, j) and sum arr[i..j]. O(n^2) time. The prefix sum in