Frontend School

Maximize Kitchen Aesthetic Value

DSA
medium

Maximize Kitchen Aesthetic Value

Medium
Dynamic Programming
1D DP
Knapsack
## Overview
Livspace designs modular kitchens, which involve arranging a sequence of pre-fabricated modules (e.g., cabinets, countertops, appliances). Each module type has an associated production cost and contributes to the overall aesthetic appeal of the kitchen. To create competitive and appealing design proposals, we need to efficiently select modules to maximize the total aesthetic value while adhering to a client's budget. This problem focuses on optimizing module selection for aesthetic return.

## What you need to do / Task
Implement a function `maximizeAestheticValue` that calculates the maximum total aesthetic value achievable given a list of available module types and a maximum budget.

- Each module type can be selected multiple times.
- The sum of costs of selected modules must not exceed the `maxBudget`.

## Input & output
**Input:**
- `modules`: An array of objects, where each object represents a module type with the following properties:
  - `cost`: A `number` representing the cost to include this module.
  - `aestheticValue`: A `number` representing the aesthetic contribution of this module.
- `maxBudget`: A `number` representing the maximum total cost allowed for all selected modules.

**Output:**
- A `number` representing the maximum possible total aesthetic value that can be achieved within the `maxBudget`.

## Clarifications
- If `modules` is empty or `maxBudget` is 0, no modules can be selected, so the maximum aesthetic value is 0.
- Modules can have a cost of 0, but for this problem, assume all `cost` values are positive integers to simplify edge cases related to infinite loops with zero-cost items.
- Aesthetic values can be 0.

Examples

1

Example 1

Input:

modules = [{cost: 10, aestheticValue: 60}, {cost: 20, aestheticValue: 100}, {cost: 30, aestheticValue: 120}], maxBudget = 50

Output:

300

Note:

To achieve a total aesthetic value of 300 within a budget of 50, you can select the module with cost 10 and aesthetic value 60, five times (5 * 10 = 50 cost, 5 * 60 = 300 aesthetic value).

2

Example 2

Input:

modules = [{cost: 5, aestheticValue: 10}, {cost: 2, aestheticValue: 3}], maxBudget = 7

Output:

13

Note:

With a budget of 7, the optimal choice is to select one module with cost 5 (value 10) and one module with cost 2 (value 3). Total cost = 5 + 2 = 7, total aesthetic value = 10 + 3 = 13.

3

Example 3

Input:

modules = [{cost: 100, aestheticValue: 10}], maxBudget = 99

Output:

0

Note:

The budget of 99 is insufficient to purchase even one module (cost 100), so the maximum aesthetic value achievable is 0.

Constraints

## Constraints & assumptions
- `1 <= modules.length <= 100`
- `1 <= modules[i].cost <= 1000`
- `0 <= modules[i].aestheticValue <= 1000`
- `0 <= maxBudget <= 10000`
- All `cost`, `aestheticValue`, and `maxBudget` values are integers.

## Out of scope
- The actual physical arrangement or layout of the modules within the kitchen space.
- Handling of negative `cost` or `maxBudget` values.
- Input validation for incorrect data types.

## What interviewers evaluate
- Correct identification and application of the Dynamic Programming paradigm.
- Efficiency of the algorithm in terms of time and space complexity.
- Robustness in handling edge cases such as empty module lists or insufficient budget.
- Clarity, readability, and modularity of the code structure.

Loading editor...