Question bank › Greedy
Dsa Greedy Medium

Maximize Product with Limited Choices

A shop has a collection of items, and each item has a limited number of units available. You are given a list of items with their corresponding values and the number of units available for each item. Your task is to maximize your product by selecting at most two distinct items. You can choose either one or two items from the list. If you select one item, it can be any of the units you have, but if you select two items, they must be distinct based on their values. Input format: - The first line contains an integer m (1 ≤ m ≤ 1000), the number of items. - The second line contains m integers v_1, v_2, ..., v_m (1 ≤ v_i ≤ 1000), the values of each item. - The third line contains m integers q_1, q_2, ..., q_m (0 ≤ q_i ≤ 100), the quantity available of each item. Output format: - Print a single integer, the maximum product possible. Example: Input: 5 1 2 3 1 4 2 1 1 0 3 Output: 12

Key concepts

greedyselectionarray

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.