FastPrepMost Cost-Effective Machine
Problems/Most Cost-Effective Machine

Most Cost-Effective Machine

Capital One logoCapital One● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Six Capital One reports from late 2021 to 2025 are grouped here. Three give a sheet of machine options or prices and want either a pick or a running cost. In two of those, the case then turned to given code that had to be read or fixed. One says the later code used that same data. Two more describe a mostly business case that also touched code reading or debugging. The sixth, an intern report, had a data-parsing technical question on hardware records in a CSV file.

No report gives the sheet's layout, which machine traits drive the cost, how time is billed, how ties break, or any numbers. Here each machine type has a core count and an hourly price. A job needs a given number of core-hours shared evenly by one machine's cores, and every started hour is billed in full. Core counts and run time are part of our model, not facts from the reports. The table is CSV text with a header line. The smallest bill wins, then fewer billed hours, then the earlier row. The limits are our choices. The code-fixing part is an editorial exercise and tests do not check it.

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

A team has one batch job to run in the cloud and wants the machine type that costs the least for it. The price list comes as CSV text in priceTable. Its first line is the header name,cores,cents_per_hour. Each line after it describes one machine type: its name, its core count, and its price in cents for every hour it runs.

The job needs coreHours core-hours of work. On a machine with c cores the work is shared evenly by all cores, so it runs for coreHours / c hours. The cloud bills every started hour as a full hour. So the machine is billed for ceil(coreHours / c) hours, and its bill is those hours times its hourly price.

Return the name of the machine type with the smallest bill. When several types share the smallest bill, choose the one billed for fewer hours. If that still leaves a tie, choose the one that appears first in the table.

Function

cheapestMachine(priceTable: String[], coreHours: int) → String

Examples

Example 1

priceTable = ["name,cores,cents_per_hour","c8.xl,8,200","c2.sm,2,60","c4.md,4,110"]coreHours = 10return = "c2.sm"
  • c8.xl needs 10 / 8 = 1.25 hours, which is billed as 2 hours, so it costs 2 × 200 = 400. Without rounding up it would have cost only 250.
  • c2.sm needs exactly 10 / 2 = 5 hours and costs 5 × 60 = 300.
  • c4.md needs 2.5 hours, billed as 3, and costs 3 × 110 = 330.
  • 300 is the lowest bill, which makes "c2.sm" the answer.

Example 2

priceTable = ["name,cores,cents_per_hour","gp-3,3,40","gp-6,6,80","hpc-12,12,170"]coreHours = 24return = "gp-6"
  • The bills are 8 × 40 = 320 for gp-3, 4 × 80 = 320 for gp-6, and 2 × 170 = 340 for hpc-12.
  • gp-3 and gp-6 share the lowest bill. gp-6 is billed for 4 hours instead of 8, so it wins even though gp-3 is listed first.

Example 3

priceTable = ["name,cores,cents_per_hour","n5,5,300","n9,9,300","n3,3,210"]coreHours = 10return = "n5"
  • n5 runs 10 / 5 = 2 hours. n9 runs about 1.11 hours, which also bills as 2. Both cost 2 × 300 = 600.
  • n3 runs about 3.33 hours, billed as 4, for 4 × 210 = 840.
  • n5 and n9 tie on both the bill and the billed hours. The extra cores of n9 do not matter, and n5 wins because it comes first in the table.

Constraints

  • 2 <= priceTable.length <= 1001, so the table lists 1 to 1000 machine types.
  • priceTable[0] is exactly "name,cores,cents_per_hour".
  • Every later line is name,cores,price with no spaces. A name is made of lowercase letters, digits, dots (.) and dashes (-), at most 20 of them and at least one; every name appears on one line only.
  • 1 <= cores <= 512 and 1 <= price <= 10^6, written as plain decimal numbers with no extra leading 0.
  • 1 <= coreHours <= 10^9

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
  • Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
  • Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025

Similar questions at other companies

  • Convert Hexadecimal to Dotted IPv4Microsoft · ONSITE INTERVIEWMicrosoft interview questions
  • Caesar Cipher with a Precomputed AlphabetAmazon · ONSITE INTERVIEW
  • Filter Contacts by Email DomainStripe · ONSITE INTERVIEWStripe interview questions
  • Flatten a Mixed JSON ListNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
  • Calculate a Token-List ExpressionCollege Vine · ONSITE INTERVIEW
  • Product Total With the Cheapest PromotionInstacart · ONSITE INTERVIEWInstacart interview questions
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Parse and Order Structured LogsCoinbase · ONSITE INTERVIEWCoinbase interview questions
  • Rank Word-Translation Hints from Sentence TranslationsDuolingo · ONSITE INTERVIEWDuolingo interview questions
  • Deep Merge with a Conflict ResolverAutodesk · ONSITE INTERVIEWAutodesk interview questions

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 String cheapestMachine(String[] priceTable, int coreHours) {
        // Write your code here.
    }
}
Checking account…