KatInterview

Topic

Arrays & Hashing interview problems

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

Problems474

134 easy303 medium37 hard

Showing 1–30 of 474 results

  • Find the shortest contiguous slice of an integer list containing exactly k different values, using a sliding window with frequency counts.

    Auto-gradedsliding-windowhash-mapsubarraytwo-pointers
  • Decide whether an ordered list of argument types fits any function in a catalog, given required, trailing optional, and variadic parameters with exact type matching.

    Auto-gradedsimulationarray-scanningsignature-matchingedge-cases
  • Find the minimum length of a contiguous subarray containing at least K unique elements using a sliding window.

    Auto-gradedsliding-windowtwo-pointershash-tablearrays
  • Determine the maximum possible gain achieved by completing at most one purchase and sale transaction over a sequence of prices.

    Auto-gradedarraysgreedyprefix-minimum
  • Build an array where each entry is the product of all other entries, without division, in linear time, using prefix and suffix running products.

    Auto-gradedprefix-productsuffix-productarrayin-place
  • Replay a sequence of marks on an n-by-n grid and report after each one whether the mover has completed a row, column or diagonal, using per-line counters.

    Auto-gradedsimulationcountingmatrixdiagonals
  • Scan an integer list and return the indices of elements strictly larger than every neighbor that exists, handling the ends, plateaus, and tiny inputs correctly.

    Auto-gradedarraystraversalboundary-conditions
  • Find the highest average speed over any 1000 m stretch of a run given per-5-second distances, using prefix sums, binary search and interpolation at boundaries.

    Auto-gradedprefix-sumsbinary-searchsliding-windowinterpolation
  • Scan an integer list for the leftmost interior value strictly smaller than both adjacent values, returning -1 if none exists, which tests boundary handling and strict comparisons.

    Auto-gradedarrayscanboundary-conditionsstrict-comparison
  • Simulate a grid game where runs of three or more equal tiles vanish together, tiles fall down, and the process repeats until the grid is stable.

    Auto-gradedsimulationmatrixtwo-pointersgrid
  • Given providers and members on a 2D plane, find members with a required specialty that has no provider within a distance limit, using hashing and spatial grouping.

    Auto-gradedhashinggeometrygrid-bucketingsimulation
  • Scan an integer list once to find the longest block of adjacent, strictly rising values, handling empty input, equal neighbors, and runs that reach the end.

    Auto-gradedarrayssliding-windowtwo-pointerslinear-scan
  • Group dated activity rows by user, find each user's earliest date, total posts in the first seven days, and compute the share of users active on day 7 or later.

    Auto-gradedhash-mapdatesaggregationcohort-analysis
  • Implement weighted index sampling with binary search and an exclusion product array without division in O(1) auxiliary space.

    Model answerarraysbinary-searchprefix-sum
  • Process a stream of possibly redelivered payment events and compute final account balances by applying each unique event ID only once.

    Auto-gradedhash-sethash-mapdeduplicationsimulation
  • Sum the shortest arc distances between consecutive stops on a ring with weighted edges, using prefix sums for O(1) arc queries.

    Auto-gradedprefix-sumcircular-arraysimulation
  • Process website activity logs to compute chronological 3-site visit subsequences and find the most widely performed pattern across unique users.

    Auto-gradedarrayshash-tablesortingsubsequence
  • Count how often each item shares a collection with a target item, then rank by count descending and name ascending, with an optional cap on the result length.

    Auto-gradedhash-mapcountingsortingco-occurrence
  • Tests in-place three-way partitioning of an array holding only 0, 1 and 2 using constant extra space and a single linear pass, with careful pointer invariants.

    Auto-gradedtwo-pointersin-placepartitioningsorting
  • Normalize ISO 8601 timestamps to UTC dates and use hashing to find users active on at least two distinct UTC calendar days.

    Auto-gradedhashingdatetimetimezonelogs
  • Group purchase records by customer, collapse same-day duplicates, and find the longest run of back-to-back calendar days, reporting results sorted by customer id.

    Auto-gradedhashingsortingdatesgaps-and-islands
  • Find every distinct set of four values, taken from different positions, that add up to a target, with no repeated value combinations in the output.

    Auto-gradedtwo-pointerssortingdeduplicationk-sum
  • Group log entries by person and ignore repeats on the same day, then count how many people appear on at least two different calendar days.

    Auto-gradedhash-sethash-mapgroupingdeduplication
  • Simulate a tile-crush game: mark all runs of 3+ equal tiles, clear them, drop tiles with gravity, and repeat until stable, counting removed tiles.

    Auto-gradedsimulationmatrixtwo-pointersgrid
  • Answer many range queries asking whether neighbors in a subarray always differ in odd/even parity, using prefix counts of same-parity adjacent pairs.

    Auto-gradedprefix-sumrange-queriesparityarrays
  • Compute the cosine of the angle between the word-frequency vectors of two strings, using a hash-map counter and guarding against empty inputs.

    Auto-gradedhash-mapcountingstringsmath
  • Count axis-aligned squares whose four corners all lie where a vertical segment meets a horizontal one, using per-row bitmasks and pairwise row comparison.

    Auto-gradedgeometrybitmaskhashingenumeration
  • Decide whether two lists of die-face labels make every total from 1 to 12 appear exactly three times across all 36 face pairings, using pair counting.

    Auto-gradedcountinghash-mapenumerationprobability
  • Group file entries that have identical byte content, using content length as a cheap first filter, and return only groups of two or more paths in a specified order.

    Auto-gradedhashinggroupingstringssimulation
  • Count contiguous non-empty segments of an integer array whose sum equals a goal, using running totals and a frequency map to handle negatives and zeros in linear time.

    Auto-gradedprefix-sumhash-mapsubarraycounting

More topics