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 121–150 of 475 results

  • Find the most profitable buy-then-sell pair in a price array when the sale must happen within D days of the purchase, in O(n) time and O(1) extra space.

    Model answersliding-windowblock-decompositionmonotonic-dequestock-trading
  • Find the maximum integer in a sequence while accounting for empty inputs and signed values.

    Auto-gradedarraysstreamingbasics
  • Cluster files that share identical byte contents by filtering first on file size metadata and then hashing content.

    Auto-gradedarrayshash mapstrings
  • Flatten a rectangular grid into a list by walking its perimeter clockwise inward, using shrinking boundaries and guards so single leftover rows or columns are not read twice.

    Auto-gradedmatrixsimulationtwo-pointersspiral
  • Group users by the month of their first activity, then compute the fraction of each cohort that was active in every later month offset, using calendar-month arithmetic.

    Auto-gradedhash-mapgroupingdatescohort-analysis
  • Apply one move on a grid: validate the target cell, find enclosed opponent runs in eight directions, and flip them together, or return the grid unchanged if no capture is possible.

    Auto-gradedgridsimulationmatrixdirections
  • Compute the mean of every full block of seven consecutive readings in a list, returning an empty list when fewer than seven readings exist; tests sliding-window technique.

    Auto-gradedsliding-windowarraysprefix-sumsnumerics
  • Reorder the two values inside every consecutive couple of a list so the smaller comes first, keeping couples in place and leaving an unpaired final value alone.

    Auto-gradedarraystwo-pointerssimulationindex-handling
  • Compute the 2D cross-correlation between a grid matrix and a filter kernel using valid padding and stride 1.

    Auto-gradedarraysmatrix
  • Return theoretical properties and compute the expected value and variance for a Binomial random variable given sample size n and success probability p.

    Auto-gradedbinomialprobabilitystatisticsmath
  • Return the k most frequent values in an integer list, ordered by count and then by first appearance, using hash counting and frequency buckets for linear time.

    Auto-gradedhash-mapbucket-sortfrequency-counttop-k
  • Map each marked grid cell to the sorted top-left corners of all in-bounds 2x2 windows that contain it, testing coordinate arithmetic and bounds handling.

    Auto-gradedgridhash-mapcoordinatesenumeration
  • Validate a nested vendor response with strict type checks, then apply ordered business rules to return the first failing reason code.

    Auto-gradedvalidationhash-maptype-checkingsimulation
  • Rearrange an array in place into its next lexicographic ordering, and evaluate a parenthesis-free arithmetic string with truncating division, both in linear time.

    Auto-gradednext-permutationtwo-pointersexpression-parsingin-place
  • Explain what three short pandas helper functions do, then propose and justify improvements to their correctness, speed, readability, robustness and testability.

    Model answerpythonpandascode-reviewvectorization
  • Compute the dot product of two run-length encoded integer vectors by walking both run lists together, without expanding them into full arrays.

    Auto-gradedtwo-pointersrun-length-encodingsimulation
  • Compute the expected value and total variance of the combined sum of two random variables given their individual means, variances, and covariance.

    Auto-gradedstatisticsprobabilitymath
  • Match call argument types against registered signatures, some with a trailing repeatable parameter, and return the sorted names of every signature that fits each call.

    Auto-gradedhashingstringsvariadic-matchingprefix-keys
  • Process an array of decimal digits representing a non-negative integer by adding one, correctly handling carry propagation and list expansion.

    Auto-gradedarraysmath-bitseasy
  • Scan sorted timestamped sensor readings once and group consecutive readings strictly above a cutoff into [first_time, last_time] windows.

    Auto-gradedarraystwo-pointersintervalssimulation
  • Simulate a synchronous grid disease model with delayed death or recovery, then try every single-row or single-column firebreak to minimize dead plants.

    Auto-gradedsimulationgridbrute-forcecellular-automaton
  • Process user experiment assignments and ride telemetry data to calculate a Welch's two-sample t-test p-value under strict filtering rules.

    Auto-gradedstatisticsdata-processinghypothesis-testing
  • Total a shopping cart where each coupon discounts one unit of its item, with percent discounts rounded half-to-even in exact integer arithmetic.

    Auto-gradedhash-mapsimulationroundinginteger-math
  • Evaluate post-matching covariate balance by computing the absolute standardized mean difference across features.

    Auto-gradedstatisticsmath-bitsarrays
  • Aggregate per-group, per-window means from daily records, compute a difference-in-differences estimate, and flag baseline drift between two pre-period sub-windows.

    Auto-gradedhashingaggregationstatisticsdate-windows
  • Construct all explicit configurations from a dictionary mapping parameter names to lists of candidate values using Cartesian product generation.

    Auto-gradedcartesian-productgeneratorarraysdictionary-manipulation
  • Find the pair of set keys with the highest intersection size, using Jaccard similarity and lexicographical order as tie-breakers via an inverted index approach.

    Auto-gradedinverted-indexhash-tablearraysstring
  • Simulate a sequence of string commands (row reversal, row swap, 90-degree clockwise turn) on a rectangular grid whose shape changes after each turn.

    Auto-gradedmatrixsimulationstring-parsingrotation
  • Compute the product of two mostly-zero integer matrices by precomputing nonzero positions so that no work is spent on zero operands.

    Auto-gradedmatrixsparsesimulationhashing
  • Compute the modular product of all elements in an array except the current element for each index without division.

    Auto-gradedarraysprefix-summath

More topics