FastPrepMinimum Cost to Process Priority Tasks
Problems/Minimum Cost to Process Priority Tasks

Minimum Cost to Process Priority Tasks

Microsoft logoMicrosoft● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Microsoft asked this as the first of two questions in a new-grad online assessment. The candidate posted a restatement they had a language model write from memory. Their own reply explained the priority cost with an example (cost 2, tasks 1 to 4 with priority tasks 1 and 3, direct cost 16). Tasks 1 to n include some priority positions. A run of tasks free of priority work is charged a flat normal time. A run that holds priority work is charged the priority time multiplied by how many priority tasks it holds and by its size, unless it is cut into two same-size parts for free and each part is handled on its own. The goal is the cheapest total.

The report did not give the input limits or how odd lengths split. Our choices: n is a power of two (so every split is exact) up to 2^20, there are up to 2 x 10^4 distinct priority positions, both times are 1 to 10^4, and the answer is a 64-bit integer.

Our version is about 85% the same as the reported question.

A CPU must process n tasks numbered 1 to n. The tasks listed in priorityTasks are priority tasks. The CPU works on contiguous groups of tasks, starting with the group of all n tasks:

  • Normal processing: a group with no priority task costs normalTime, whatever its size.
  • Priority processing: a group with priority tasks can be processed directly for priorityTime × count × length, where count is the number of priority tasks in the group and length is the number of tasks in the group.
  • Splitting: instead, a group with more than one task may be split into two equal halves (the first half and the second half), and each half is processed the same way. Splitting itself costs nothing.

n is a power of two, so every split is exact. Return the minimum total time to process all n tasks.

Function

minProcessingTime(n: int, priorityTasks: int[], normalTime: int, priorityTime: int) → long

Examples

Example 1

n = 4priorityTasks = [1,3]normalTime = 1priorityTime = 2return = 6
  • Processing all four tasks at once costs 2 × 2 × 4 = 16.
  • Splitting into [1, 2] and [3, 4]: each half has one priority task. Directly each costs 2 × 1 × 2 = 4, but splitting again gives [1] (cost 2 × 1 × 1 = 2) and [2] (no priority task, cost 1), so 3 per half.
  • The total is 3 + 3 = 6.

Example 2

n = 8priorityTasks = []normalTime = 5priorityTime = 3return = 5
  • There are no priority tasks, so processing all 8 tasks as one group costs normalTime = 5.

Example 3

n = 2priorityTasks = [1,2]normalTime = 10priorityTime = 1return = 2
  • Directly: 1 × 2 × 2 = 4. Split: 1 + 1 = 2. The answer is 2.

Constraints

  • n = 2m for some integer 0 <= m <= 20, so 1 <= n <= 220.
  • 0 <= priorityTasks.length <= 2 × 104
  • 1 <= priorityTasks[i] <= n, and all values in priorityTasks are distinct.
  • 1 <= normalTime, priorityTime <= 104

More Microsoft Online Assessment questions

  • Most Visited Sprint MarkerOA · Seen Nov 2026
  • Maximum Escape Game ScoreOA · Seen Nov 2026
  • Count Subarrays with a Perfect-Square ProductOA · Seen Nov 2026
  • Maximum Interactive Team SizeOA · Seen Nov 2026
  • Maximize Pipeline Throughput Under a Scaling BudgetOA · Seen Nov 2026
  • Minimum Cost K-Capable ModelsOA · Seen Nov 2026
  • Find Available Meeting RoomsOA · Seen Oct 2026
  • Maximum Sum of a K-StarOA · Seen Oct 2026
  • Capacity to Ship Packages Within DaysOA · ONSITE INTERVIEW · Seen Oct 2026
  • Count Digit Replacements with No Equal Adjacent DigitsOA · Seen Oct 2026

Similar questions at other companies

  • AVL Insertion and RotationsSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
  • Delete Node in a BSTBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Delete Node in a BSTTokopedia · PHONE SCREENTokopedia interview questions
  • Recursive Binary SearchEPAM · ONSITE INTERVIEWEPAM interview questions
  • Out-of-Order Bank Ledger BalancesPerplexity AI · OAPerplexity AI interview questions
  • Server Upgrade PlanningWells Fargo · OAWells Fargo interview questions
  • Find Minimum TimeAlphaSense · OA
  • Subscription and Usage-Based Billing CalculatorStripe · OAStripe interview questions
  • Find Minimum TimeBlackRock · OABlackRock interview questions
  • Perfect Squares Matching a PatternNielsen · OA

Microsoft interview experiences

  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public long minProcessingTime(int n, int[] priorityTasks, int normalTime, int priorityTime) {
        // Write your code here.
    }
}
Checking account…