This is a verified interview question from Microsoft. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Plan Production - Microsoft OA IIT Roorkee" covers key patterns like Other.
"You must plan production for a company that manufactures multiple products. Each product has two associated costs: - A worst-case cost that must be available before production begins - An expected cost that is actually spent during production Determine the minimum amount of starting cash needed to manufacture all products. Products can be produced in any order, and after completing each product, the remaining cash can be used for subsequent products. ### Problem You are given two integer arrays, `worstCase` and `expected`, where `worstCase[i]` and `expected[i]` represent the worst-case and expected costs for product `i`, respectively. The goal is to find the minimum starting cash required to produce all products in any order. ### Input - `worstCase`: An integer array representing the worst-case costs for each product. - `expected`: An integer array representing the expected costs for each product. ### Output - The minimum starting cash required to produce all products. ### Example - `worstCase = [6, 5, 7]`, `expected = [4, 2, 1]`: The optimal production order is `2, 1, 0`, requiring a minimum starting cash of `9` units. - `worstCase = [6, 7, 8]`, `expected = [4, 4, 7]`: The optimal production order is `(0,2,1)`, requiring a minimum starting cash of `10` units. - `worstCase = [6, 7, 8]`, `expected = [4, 4, 7]`: The optimal production order is `(0,1,2)`, requiring a minimum starting cash of `16` units."
Join thousands of developers practicing for Microsoft.