FastPrepMaximum Total Number of Orders Fulfilled
Problems/Maximum Total Number of Orders Fulfilled

Maximum Total Number of Orders Fulfilled

Microsoft logoMicrosoft● EasyOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

A technology company announced that a new supply of P monitors would soon be available at their store. There were N orders (numbered from 0 to N-1) placed by customers who wanted to buy those monitors. The K-th order has to be delivered to a location at distance D[K] from the store and is for exactly C[K] monitors.

Now the time has come for the monitors to be delivered. The orders will be fulfilled one by one. To minimize the shipping time, it has been decided that the deliveries will be made in order of increasing distance from the store. If there are many customers at the same distance, they can be processed in any order. Monitors to more distant customers will be delivered only once all orders to customers closer to the store have already been fulfilled.

What is the maximum total number of orders that can be fulfilled?

Function

solution(D: int[], C: int[], P: long) → int

Write a function:

class Solution { public int solution(int[] D, int[] C, long P); }

that, given two arrays of integers D and C, and a long integer P, returns the maximum total number of orders that can be fulfilled.

Examples

Example 1

D = [5, 11, 1, 3]C = [6, 1, 3, 2]P = 7return = 2

The customers at distances 1 and 3 will have their orders fulfilled and 3 + 2 = 5 monitors will be delivered.

Example 2

D = [10, 15, 1]C = [10, 1, 2]P = 3return = 1

Only the order for the customer at distance 1 will be fulfilled. There will not be enough monitors in the store for the customer at distance 10. Therefore, orders for customers at distances 10 and 15 will not be fulfilled.

Example 3

D = [11, 18, 1]C = [9, 18, 8]P = 7return = 0

There are not enough monitors to fulfill any orders.

Example 4

D = [1, 4, 2, 5]C = [4, 9, 2, 3]P = 19return = 4

All orders can be fulfilled as there are enough monitors available.

Constraints

  • N is an integer within the range [1..100,000].
  • Each element of arrays D and C is an integer within the range [1..1,000,000,000].
  • P is an integer within the range [0...10,000,000,000].

More Microsoft interview questions

  • Config Store with Priority OverridesPHONE SCREEN · Seen Nov 2026
  • Authentication SystemOA · Seen Nov 2026
  • Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
  • Maximum String OperationsOA · Seen Nov 2026
  • Minimum Cost to Process Priority TasksOA · Seen Nov 2026
  • Most Visited Sprint MarkerOA · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Maximum Apples That Fit in a BoxVirtu Financial · OAVirtu Financial interview questions
  • Server ManagementRippling · OARippling interview questions
  • Maximum Three-Server Difficulty ScoreVisa · OAVisa interview questions
  • Economical TripAccenture · OAAccenture interview questions
  • Minimum Pile Reduction StepsAmerican Express · OAAmerican Express interview questions
  • Find Maximum Number of Subjects Passed (AS Intern, but it may apply to other interns) 🍋Amazon · OA
  • Maximum Production Within PowerZomato / Eternal · OAZomato / Eternal interview questions
  • Can Every Package Fit in a BoxIMC Trading · OAIMC Trading interview questions
  • Compute Walking DistanceTikTok · OATikTok interview questions

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • 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)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int solution(int[] D, int[] C, long P) {
       // write your code here
    }

}
Checking account…