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 61–90 of 475 results

  • Evaluate posterior coin probabilities, posterior predictive likelihoods, and expected stopping times following observed heads.

    Auto-gradedprobabilitybayes-theoremexpected-valuebayesian-inference
  • Find the longest contiguous strictly increasing window in an integer array after replacing at most one element with any integer, using prefix and suffix run lengths.

    Auto-gradedarrayssliding-windowprefix-suffixdynamic-programming
  • Group timestamped events by user, order them in time, and count how many distinct users share each opening action sequence of length up to k.

    Auto-gradedhash-mapgroupingsortingprefixes
  • Shift an integer array left or right by k using modular arithmetic, then locate every occurrence of one or more keywords in a simple CSV string, reporting row, column and offset in the cell.

    Model answerarray-rotationmodular-arithmeticstring-searchcsv-parsing
  • Normalize directed city pairs into unordered ones, remove duplicates, and return them in sorted order, testing canonicalization with hashing and sorting.

    Auto-gradedhashingsortingdeduplicationcanonical-form
  • Normalize IPv4/IPv6 strings, skip invalid ones, count occurrences, and return the top ten addresses while keeping every address tied at the tenth-place frequency.

    Auto-gradedhash-mapcountingsortingstring-parsing
  • Simulate a clockwise inward walk over a grid with obstacle cells, turning on edges, obstacles and visited cells, and stopping when every direction is closed.

    Auto-gradedmatrixsimulationspiralgrid
  • Find the maximum gain possible from buying and selling a stock once, given a sequence of daily values.

    Auto-gradedarraysgreedydynamic-programming
  • Count subarrays where the number of elements congruent to a residue, taken modulo the same base, equals that residue, using prefix remainders and a frequency table.

    Auto-gradedprefix-sumhash-mapmodular-arithmeticsubarrays
  • Group users by first-activity month and compute the share who return exactly 30 days later, excluding users whose day 30 lies beyond the last observed date.

    Auto-gradedhash-mapdatescohort-analysisgrouping
  • Combine three closed-form statistics results: the lowest shared correlation of three variables, a reverse regression slope from R² and a slope, and the covariance of the max and min of two uniforms.

    Auto-gradedcorrelationlinear-regressionorder-statisticscovariance
  • Find the largest total of any k consecutive values in a list, testing fixed-size sliding window technique and the ability to avoid recomputing overlapping sums.

    Auto-gradedsliding-windowarraysprefix-sum
  • Find the longest stretch of 1s achievable in a binary list when at most one 0 may be changed to 1, using a two-pointer window that tolerates one zero.

    Auto-gradedsliding-windowtwo-pointersbinary-array
  • Perform quantitative financial modeling and sensitivity analysis for renewable energy pilot projects.

    Auto-gradedfinancesensitivity-analysismathstatistics
  • Return the next-success probability under independence, plus a pooled two-proportion z statistic and two-sided p-value comparing two success rates.

    Auto-gradedhypothesis-testingtwo-proportion-z-testconditional-probabilitynormal-distribution
  • Simulate placing fixed binary shapes onto a grid at the first row-major position where their filled cells hit only empty cells, labelling each by its index.

    Auto-gradedsimulationmatrixgridbrute-force
  • Count contiguous non-empty subarrays whose elements sum to a goal value, using running prefix sums with a frequency map to handle negatives and zeros in linear time.

    Auto-gradedprefix-sumhash-mapsubarraycounting
  • Find the minimum length of a contiguous block of an integer list containing at least k different values, using a sliding window with a frequency map.

    Auto-gradedsliding-windowtwo-pointershash-map
  • Convert a flat list of throws into a ten-frame total, applying look-ahead bonuses for strikes and spares, including fill throws in the last frame.

    Auto-gradedsimulationarraylook-aheadpointer-walk
  • Tests using a hash-based structure to drop repeated values from a list while keeping first-occurrence order, in linear time and without modifying the input.

    Auto-gradedhash-setordered-dictarraysdeduplication
  • Build a service that checks a city's latitude, pulls a 72-hour forecast from an unreliable API with proper retries, and returns every 8-hour span of strictly falling, gapless hourly temperatures.

    Model answersliding-windowretry-backoffapi-integrationerror-handling
  • Tests hashing and counting over text: tokenize, compute smoothed IDF for query terms, score every document, and sort by descending score with an index tie-break.

    Auto-gradedhashingtf-idftokenizationsorting
  • Simulate an in-memory key-value dictionary given a sequence of insertion, lookup, and deletion instructions.

    Auto-gradedarrayshash-mapdata-structuresdesign
  • Parse a JSON list of account records with exact decimal arithmetic, drop invalid rows, keep the newest record per account, and report a rounded total plus a per-account map.

    Model answerpythonjsondecimaldeduplication
  • Concatenate truncated token lists into equal-length blocks, zero-pad the last one, and build a parallel 0/1 mask marking real tokens versus padding.

    Auto-gradedarrayssimulationtwo-pointersbatching
  • Cluster words that share identical letter counts into ordered buckets, using a hashable frequency key rather than sorting each word's letters, while preserving duplicates and order.

    Auto-gradedhash-mapstringsanagramsfrequency-count
  • Filter streaming events by duration and date window, count plays per track, and produce a global top 5 and per-country top 3 with deterministic tie-breaking.

    Auto-gradedhash-mapcountingsortinggrouping
  • Tests using a hash set alongside a list to filter repeated integers in one pass while preserving first-appearance order, in linear time.

    Auto-gradedhash-setarraysdeduplicationorder-preservation
  • Pair sign-in and sign-out events per user from an unsorted log using chronological order and FIFO matching, and report users with a session within a time limit.

    Auto-gradedhash-mapsortingqueuesimulation
  • Simulate k-means++ seeding with a fixed RNG protocol, then run two assign/update rounds and report clusters, centroids and final squared error.

    Auto-gradedsimulationclusteringrandomized-samplingfloating-point

More topics