FastPrepCashback Tracker
Problems/Cashback Tracker

Cashback Tracker

Capital One logoCapital One● MediumINTERNNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Two 2025 Capital One reports cover this exercise. An intern report from Canada describes a staged object-oriented exercise: purchase tracking came first, refunds and a per-month ranking were added as follow-ups, and handling more customers was only discussed. A TDP new grad report from McLean names a credit card cashback question solved with dictionaries.

Neither report gives the call format, how cashback is worked out, how a refund changes it, what the ranking lists, how ties break, or any limits. Here you get the calls as an array of strings, and only TOTAL and TOP give answers. A purchase earns its whole dollars times its own percent rate, in cents. A refund can return part or all of a purchase and takes cashback back at that purchase's rate, inside the purchase's own month. TOTAL covers every month. TOP ranks single purchases by the cashback they still have, with ties going to the lower id, leaves out fully refunded purchases, and returns a shorter row when fewer than n qualify. The limits on ids, dates, amounts, rates, n and the number of calls are our choice. Handling many customers is covered in the editorial and is not checked.

Overall, our version is about 70% the same as the reported questions.

One customer uses a credit card that pays cashback on each purchase. Write a tracker that keeps this cashback up to date and answers two questions: the customer's total cashback, and which purchases of a given month have the most cashback left.

A purchase of dollars whole dollars at a rate of percent% earns dollars × percent cents. A refund hands back part or all of one purchase. The purchase keeps its rate and its date, and its cashback becomes (dollars it still keeps) × percent cents. The same purchase may be refunded several times, until nothing of it is left.

The total is the cashback of every purchase so far, from any month, after refunds. The top list for a month and a number n holds at most n ids. They come from the purchases dated in that month whose cashback is still above 0, taken in order of the pair (cashback left, id): higher cashback first and, for equal cashback, lower id first.

Each string of calls is one of "PURCHASE id date dollars percent", "REFUND id dollars", "TOTAL" and "TOP month n", where date looks like YYYY-MM-DD and month like YYYY-MM. Handle them in array order. A TOTAL call adds the row [total] to the returned array, and a TOP call adds its list of ids as a row, possibly empty. Purchases and refunds add no row.

Function

trackCashback(calls: String[]) → int[][]

Examples

Example 1

calls = ["PURCHASE 31 2025-03-04 80 2","PURCHASE 7 2025-04-19 250 1","PURCHASE 12 2025-03-28 45 5","PURCHASE 5 2025-03-11 120 1","TOTAL","TOP 2025-03 2"]return = [[755],[12,31]]
  • Each purchase earns dollars times percent in cents: purchase 31 earns 80 × 2 = 160, purchase 7 earns 250 × 1 = 250, purchase 12 earns 45 × 5 = 225, and purchase 5 earns 120 × 1 = 120.
  • TOTAL counts every month, so it gives 160 + 250 + 225 + 120 = 755.
  • TOP 2025-03 2 only looks at the March 2025 purchases 31, 12 and 5; purchase 7 is from April. Their cashback is 160, 225 and 120, and the two largest belong to 12 and then 31.

Example 2

calls = ["PURCHASE 3 2024-11-02 200 3","PURCHASE 8 2024-11-15 150 5","PURCHASE 4 2024-11-30 90 4","TOP 2024-11 3","REFUND 8 70","REFUND 4 90","TOP 2024-11 3","TOTAL","TOP 2024-12 1"]return = [[8,3,4],[3,8],[1000],[]]
  • Before any refund, purchase 3 has 200 × 3 = 600 cents, purchase 8 has 150 × 5 = 750 and purchase 4 has 90 × 4 = 360, so the first TOP gives [8,3,4].
  • Purchase 8 gets 70 of its 150 dollars back. The 80 dollars it keeps still earn 5%, so it now has 80 × 5 = 400 cents. It lost 70 × 5 = 350 cents, not 70.
  • Purchase 4 gets all 90 dollars back, so it has 0 cents and is left out of later TOP rows.
  • Now 600 > 400, so the second TOP gives [3,8]: only two ids, although n = 3. TOTAL gives 600 + 400 + 0 = 1000.
  • Nothing was bought in December 2024, so TOP 2024-12 1 gives the empty row [].

Example 3

calls = ["PURCHASE 52 2027-06-03 90 2","PURCHASE 8 2027-06-11 36 5","PURCHASE 60 2027-06-20 50 4","PURCHASE 23 2027-06-27 70 1","REFUND 60 5","TOP 2027-06 4","TOTAL"]return = [[8,52,60,23],[610]]
  • Purchase 52 has 90 × 2 = 180 cents, purchase 8 has 36 × 5 = 180, purchase 60 has 50 × 4 = 200 and purchase 23 has 70 × 1 = 70.
  • Refunding 5 dollars of purchase 60 leaves 45 dollars, so it falls from 200 to 45 × 4 = 180 and joins 52 and 8 at 180.
  • Inside that group of three, ids run from low to high: 8, then 52, then 60. So 8 leads although 52 was bought before it, and 60, which led before the refund, is now last of the three. Purchase 23 follows with 70, and n = 4 keeps all four: [8,52,60,23].
  • TOTAL gives 180 + 180 + 180 + 70 = 610.

Constraints

  • 1 <= calls.length <= 2000
  • Every string in calls is a PURCHASE, REFUND, TOTAL or TOP call written as in the statement, with one space between parts; ids, dollars, percents and n are positive whole numbers whose first digit is not 0.
  • Each id lies between 1 and 10^9, and no two PURCHASE calls use the same id.
  • Every date is a real calendar date from 2020-01-01 to 2029-12-31, and every month is from 2020-01 to 2029-12.
  • In a PURCHASE, 1 <= dollars <= 10^5 and 1 <= percent <= 5.
  • A REFUND names the id of an earlier PURCHASE, and its dollars is at least 1 and at most the part of that purchase not refunded yet.
  • In a TOP, 1 <= n <= 2000.
  • At least one call is TOTAL or TOP.

More Capital One Onsite Interview questions

  • Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
  • Sort ColorsONSITE INTERVIEW · Seen Oct 2026
  • Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
  • Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
  • Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
  • Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
  • Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
  • Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025
  • Most Cost-Effective MachineONSITE INTERVIEW · Seen Sep 2025

Similar questions at other companies

  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Camel CardsRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Calendar Event System with Pagination and IntersectionLead Bank · ONSITE INTERVIEWLead Bank interview questions
  • CD Rental SystemOkta · ONSITE INTERVIEWOkta interview questions
  • Order Manager with Partial Cancellations and Indexed QueriesStripe · ONSITE INTERVIEWStripe interview questions
  • Set Command SimulationPure Storage · ONSITE INTERVIEWPure Storage interview questions
  • Worker Management with Promotions and Double-Paid TimeInstacart · ONSITE INTERVIEWInstacart interview questions
  • Banking System with Pending Transfer AcceptanceCircle · PHONE SCREENCircle interview questions
  • Streaming Top-K Frequent ElementsNVIDIA · PHONE SCREENNVIDIA interview questions
  • Temporal Key-Field Database with Prefix ScansThe Trade Desk · OA

Capital One interview experiences

  • Capital One Experienced Engineer Power Day and OA: 6 Experiences
  • Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
  • Capital One TDP Agentic Round (AI Coding): 7 Experiences
  • Capital One SWE Power Day, Level Not Reported: 6 Experiences
  • Capital One TIP Intern OA and Power Day: 13 Experiences
  • Capital One TDP Agentic Power Day: 25 Experiences (Part 1 of 2)
All Capital One interview questionsSee Capital One hiring insights
Saved
class Solution {
    public int[][] trackCashback(String[] calls) {
        // Write your code here.
    }
}
Checking account…