KatInterview

Topic

Arrays & Hashing interview problems

Two pointers, prefix sums, hash maps and sliding windows. 477 original problems, each with hidden test cases you can run in the browser.

Problems477

137 easy303 medium37 hard

Showing 211–240 of 477 results

  • Find the leftmost column holding a 1 in a binary grid whose rows are sorted, aiming for a linear-time walk instead of scanning every cell.

    Auto-gradedmatrixtwo-pointersbinary-matrixstaircase-search
  • Group impression records by country and user over a 7-day window, flag users with 4+ active dates and 3+ surfaces on one date, and report per-country percentages.

    Auto-gradedhash-mapgroupingsetsdate-handling
  • Find the shortest contiguous block whose removal leaves a non-decreasing array, using sorted prefix/suffix boundaries and two pointers, with a smallest-start tie-break.

    Auto-gradedtwo-pointersarraysprefix-suffixgreedy
  • Decide whether one value from each of two sorted lists adds up to a target, using a linear-time opposite-direction two-pointer scan with constant extra space.

    Auto-gradedtwo-pointerssorted-arraystwo-sumoverflow-safety
  • Estimate a population-wide event rate from samples drawn with known unequal inclusion probabilities, using inverse-probability weighting divided by the population size.

    Auto-gradedinverse-probability-weightingsamplingestimationhorvitz-thompson
  • Simulate a rover on a bounded rectangular grid that turns, steps forward, and steps backward, skipping any step that leaves the grid or enters a blocked cell.

    Auto-gradedsimulationhash-setgridmodular-arithmetic
  • Count positions whose removal makes the sum at even positions equal the sum at odd positions, testing prefix/suffix sums and the parity shift after a deletion.

    Auto-gradedprefix-sumsparityarraycounting
  • Join order, product and category records, group by category name, and compute total revenue, mean revenue per row and the share of completed rows, using hash maps.

    Auto-gradedhash-mapaggregationjoingrouping
  • Sort card authorization events by time and apply permanent, time-activated block rules to label each as APPROVE or REJECT, testing stable sorting, two-stream merging and hashing.

    Auto-gradedhashingsortingsimulationtwo-pointers
  • Design a way to merge two key-value maps, extend it to k maps, and decide which conflict rules must be pinned down before writing any code.

    Model answerhash-mapmergingapi-designclarifying-questions
  • Fill None cells in a table column by column with the mean, median or smallest-most-frequent value of the observed entries, without mutating the input.

    Auto-gradedarrayssimulationstatisticsdata-cleaning
  • Fill in the blanks of a 9x9 digit grid so every row, column and 3x3 block holds each digit 1-9 once, testing backtracking with constraint pruning.

    Auto-gradedbacktrackingconstraint-satisfactionbitmaskrecursion
  • Compute total rainwater stored between unit-width columns of given heights, aiming for a single pass with constant extra memory using the two-pointer technique.

    Auto-gradedtwo-pointersarraysgreedy
  • Find the two distinct positions in an integer list whose values sum to a goal, using a single-pass hash map lookup instead of checking every pair.

    Auto-gradedhash-maparrayscomplement-lookup
  • Compute the per-group sample size for a two-proportion test from a given formula, and update a Beta prior with observed Bernoulli outcomes.

    Auto-gradedstatisticspower-analysisbayesian-updatebeta-binomial
  • Count senders and receivers from signed transfer records in a single pass, then pick the five most frequent on each side with a deterministic tie-break.

    Auto-gradedhash-mapcountingheapstreaming
  • Build a new list that alternates positives and negatives (starting positive), keeps same-sign order, appends leftover elements, and places zeros last.

    Auto-gradedarraystwo-pointersstable-partitionsimulation
  • Combine a prefix-sum hash map to count contiguous slices summing to a target with a grid flood fill to find the largest 4-connected cluster of buildings.

    Auto-gradedprefix-sumhash-mapflood-fillgrid
  • Sliding-window problem: for each end index find the shortest suffix with at least 1000 meters, compute its average speed, and return the maximum across all end indices.

    Auto-gradedsliding-windowtwo-pointersprefix-sumsarrays
  • Scan a list of employee records and keep those meeting every enabled optional range or membership rule, preserving order and leaving the input untouched.

    Auto-gradedfilteringhash-setoptional-parameterssimulation
  • Simulate a fit/predict command sequence for a linear model trained with batch gradient descent on mean squared error, using plain Python lists.

    Auto-gradedgradient-descentlinear-regressionmsesimulation
  • Count contiguous subarrays whose sum has a given remainder using prefix-sum remainders, and delete the fewest parentheses to balance a string in a fixed, deterministic way.

    Auto-gradedprefix-summodular-arithmetichash-countinggreedy
  • Process payments in order, pairing each with an invoice by ID plus amount, then by unique amount, then by closest amount within a percentage tolerance.

    Auto-gradedhash-mapsimulationmatchingfloating-point
  • Simulate a marble on a grid whose tilt changes at scheduled times, and find its final cell efficiently when the end time can reach a billion seconds.

    Auto-gradedsimulationgridtime-segmentstwo-pointers
  • Find the largest gain from buying and later selling the same ticker on a strictly later date, given an unsorted log with duplicate dates; tests grouping, sorting and careful running-minimum updates.

    Auto-gradedhash-mapsortinggreedytime-series
  • Tests hash-map frequency counting: find every string occurring more than once in a list and report its count, using exact comparison.

    Auto-gradedhash-mapcountingstringsfrequency
  • Randomly assign eligible ads to page positions for one user, respecting per-user display caps, avoiding repeats when possible, and returning the updated view counts.

    Model answerrandomizationhash-mapshuffleresource-allocation
  • Count occurrences of each string in a list with a hash map, then rank by count with an alphabetical tie-break to extract the top three entries.

    Auto-gradedhash-mapcountingsortingtie-breaking
  • Compute the smallest equal group size for a two-sided two-proportion z-test, given a baseline rate, relative uplift, significance level and target power.

    Auto-gradedstatisticssample-sizepower-analysisab-testing
  • Enumerate every subarray whose length is a power of two and whose sum falls in [k, 2k], using prefix sums to get an O(n log n) solution with ordered output.

    Auto-gradedprefix-sumsliding-windowsubarrayenumeration

More topics