FastPrepDeduplicate Card-Pile Prefixes
Problems/Deduplicate Card-Pile Prefixes

Deduplicate Card-Pile Prefixes

Google logoGoogle● HardNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Three firsthand reports describe the two-list example and the general rule about the previous d piles. We fixed a scan that deletes the fewest cards and leaves the rest unchanged after k valid prefix cards. Our version is about 93% the same as the combined reported questions.

Process card piles from left to right. For pile i, its cleaned first k cards must contain no value that appears among the cleaned first k cards of any of the previous d piles.

Clean a pile by scanning it from left to right and deleting the minimum possible number of conflicting cards until either k valid prefix cards have been kept or the pile ends. Once k valid prefix cards have been kept, keep the rest of the pile unchanged, because cards after the first k kept cards do not take part in comparisons.

The first pile has no earlier restrictions. Return all cleaned piles in their original order. When fewer than d earlier piles exist, compare against all of them. k may exceed a pile's final length.

Function

cleanPilePrefixes(piles: int[][], k: int, d: int) → int[][]

Examples

Example 1

piles = [[3,2,4,5,2],[2,1,3,4]]k = 2d = 1return = [[3,2,4,5,2],[1,4]]

The second pile deletes 2 and 3 so its cleaned first two cards, [1,4], avoid [3,2].

Example 2

piles = [[1,2,9],[2,3,8],[1,4,7,5]]k = 2d = 2return = [[1,2,9],[3,8],[4,7,5]]

Each later prefix avoids the union of up to two previous cleaned prefixes.

Example 3

piles = [[1],[1,1],[1,2]]k = 2d = 1return = [[1],[],[1,2]]

The empty cleaned second pile contributes no forbidden prefix values to the third pile.

Constraints

  • 1 <= piles.length <= 100000.
  • The total number of cards is at most 200000.
  • 0 <= k,d <= 100000.
  • Card values are signed 32-bit integers.

More Google Onsite Interview questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Sliding Window MedianNotion · ONSITE INTERVIEWNotion interview questions
  • Sliding Window MedianBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Shortest Window with Required CountsOracle · ONSITE INTERVIEWOracle interview questions
  • Count Zero Request ServersSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Longest Subarray with K Distinct ValuesAmazon · ONSITE INTERVIEW
  • Count Equal Code Pairs Within Distance KInfosys · ONSITE INTERVIEWInfosys interview questions
  • Longest Subarray with At Most Two Distinct ValuesMoody's Investors Service · ONSITE INTERVIEW
  • Maximum Sum of a Unique-Element SubarrayTekion · ONSITE INTERVIEWTekion interview questions
  • Sliding Window: Target Containment and Most-Repeated WindowRoblox · ONSITE INTERVIEWRoblox interview questions
  • Duplicate Transactions Within 60 SecondsCapital One · ONSITE INTERVIEWCapital One interview questions

Interview reports that mention this question

  • Google New Grad SWE Interview Questions Guide (Part 1 of 2)
  • Google PhD ML New Grad Virtual Onsite: 1 Experience

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int[][] cleanPilePrefixes(int[][] piles, int k, int d) {
        // Write your code here.
    }
}
Checking account…