KatInterview

Topic

Arrays & Hashing interview problems

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

Problems475

135 easy303 medium37 hard

Showing 91–120 of 475 results

  • Find the length of the longest contiguous stretch of an integer array in which no value appears twice, using a sliding window with a last-seen index map.

    Auto-gradedsliding-windowhash-maptwo-pointerssubarray
  • Debug a small spending-limit module with failing tests: find root causes, fix them, add minimal regression tests, and explain your debugging process and tools.

    Model answerdebuggingunit-testingroot-cause-analysisfloating-point
  • Compute, for every empty cell, the gap to the nearest blocker in each of four directions using linear sweeps, then return the cells whose four gaps equal a given target.

    Auto-gradedgridmatrixprefix-sweepsimulation
  • Process sequential database schema snapshots to assign permanent, case-insensitive unique column aliases with automatic collision resolution.

    Auto-gradedarraysstringsdesign-ds
  • Filter a list of record dictionaries so only the first record for each identifier remains, preserving order and doing it in a single linear pass with a hash set.

    Auto-gradedhash-setdeduplicationarraysorder-preservation
  • Finds all unique value triplets in an integer array that sum to a specified target using sorting, two-pointer scanning, and pruning.

    Auto-gradedarraystwo-pointerssortingdeduplication
  • Count items by their string form and return every label tied for the highest count, in first-appearance order, without calling max().

    Auto-gradedhash-mapcountingfrequencyties
  • Find all possible values of the minimum non-negative excluded integer (MEX) achievable after at most one element increment.

    Auto-gradedarrayshash-tablefrequency-arraymath
  • Given a batch of 2D routes, compute for each waypoint the length of the remaining route to the final waypoint, in linear time, handling short and empty inputs.

    Model answersuffix-sumnumpyvectorizationeuclidean-distance
  • Normalize a piecewise-linear triangular density to find its constant, then evaluate the resulting piecewise-quadratic cumulative distribution at a list of query points.

    Auto-gradedprobabilitycdfpiecewise-functionsintegration
  • Merge duplicate timestamps by averaging known readings, sort, then fill missing values by linear interpolation inside gaps and nearest-value holding at the ends.

    Auto-gradedhash-mapsortinginterpolationtime-series
  • Decide whether any two elements at different positions in an integer list add up to a given value, testing hash-set lookups and careful handling of duplicates.

    Auto-gradedhash-settwo-sumarrayscomplement
  • Decide, for every k, whether the values 1..k occupy a contiguous block of a permutation, using value positions and a running span instead of scanning subarrays.

    Auto-gradedpermutationindex-mappingrunning-min-maxstring-output
  • Turn a square integer grid a quarter turn clockwise by modifying it in place, testing index mapping and in-place transforms such as transpose plus row reversal.

    Auto-gradedmatrixin-placesimulationtranspose
  • Find the minimum combined cost of an outbound and return ticket where return happens strictly after departure.

    Auto-gradedarraysgreedyprefix-minimum
  • Find users whose event log contains at least seven consecutive UTC calendar days of activity, using per-user day deduplication and a sorted streak scan.

    Auto-gradedhashingdatesstreakssorting
  • Find the maximum non-negative profit from purchasing an asset on one day and selling it on a subsequent day.

    Auto-gradedarraysdynamic-programminggreedy-intervals
  • Group records by composite row and column keys, sum a value field per pair, and return the axes in first-seen order with a dense grid that has zeros for missing pairs.

    Auto-gradedhash-mapgroupingaggregationtuples
  • Simulate a grid where tokens are pushed in from the bottom of a column, and after each push report success and whether any full column or full row is single-typed.

    Auto-gradedsimulationmatrixstate-trackinggrid
  • Scan a time-ordered list of library events and verify each item's history strictly alternates borrow, return, starting with a borrow, using per-item state tracking.

    Auto-gradedhash-setstate-trackingsimulationvalidation
  • Scan a list of integer 2D points once to find the extreme x and y values, then report the enclosing axis-aligned box as a corner plus width and height.

    Auto-gradedarraysgeometrymin-maxsingle-pass
  • Compute the share of 2023 total expenditure contributed by users who met a high-tier spending threshold in 2022.

    Auto-gradedarrayshash tabledata manipulationcohort analysis
  • Scan a sorted list of distinct integers once to report every maximal run of integers in a closed window that the list skips, formatting single gaps as one-element lists.

    Auto-gradedarraysintervalstwo-pointersedge-cases
  • Replay timestamped start/stop events in time order, with ties broken by input position, tracking one active job per category, and confirm the log is valid and fully closed.

    Auto-gradedhash-setsortingsimulationstate-tracking
  • Determine if two distinct cells in a 2D matrix sum to a target integer while processing elements in spiral order.

    Auto-gradedarrayshash-tablematrix
  • Find the most disjoint pairs in an integer list whose sum equals a goal, using value counts or sorting with two pointers, while handling duplicates, negatives and the half-goal case.

    Auto-gradedhash-maptwo-pointersgreedycounting
  • Find the most index-disjoint pairs in an integer array whose values add up to a target, testing hashing of complements, counting, and handling of the self-pairing case.

    Auto-gradedhash-mapcountingtwo-pointersgreedy
  • For each shopper on a line, find the closest stall index, with ties going to the lower index, testing two-sided linear scans for nearest-neighbor lookups.

    Auto-gradedarraystwo-pointersprefix-suffixnearest-neighbor
  • Count index pairs i < j whose values differ by exactly k, using a frequency map and handling the k = 0 case separately to avoid double counting.

    Auto-gradedhash-mapcountingfrequencypairs
  • Filter add-to-cart events, convert UTC to Pacific dates, merge rapid repeats into single actions with a chained gap rule, and count the actions per user, date and SKU.

    Auto-gradedhashinggroupingdatetimetimezones

More topics