Frontend School

Nykaa Beauty Box Customization

DSA
medium

Nykaa Beauty Box Customization

Medium
Dynamic Programming
Knapsack
Arrays

Overview

Nykaa aims to offer highly personalized beauty experiences. One such initiative is the "Curated Beauty Box", where customers can select products to build a custom box. To ensure a premium experience while managing inventory and costs, there are specific constraints on each box. This problem focuses on optimizing product selection for a customer's beauty box.

What you need to do / Task

You are tasked with implementing a function maximizeBeautyBoxValue that determines the maximum total beauty score of products that can be included in a customer's beauty box. You must select products such that:

  1. The total price of selected products does not exceed a given maxBudget.
  2. The total number of selected products does not exceed a given maxItems.
  3. Each product can be selected at most once.

Input & output

Input:

  • products: An array of objects, where each object has two properties: price (number) and beautyScore (number).
  • maxBudget: A number representing the maximum total price allowed for products in the box.
  • maxItems: A number representing the maximum number of products allowed in the box.

Output:

  • A number representing the maximum total beautyScore achievable under the given constraints.

Clarifications

  • If no products can be selected within the constraints, the function should return 0.
  • All price and beautyScore values will be non-negative integers. maxBudget and maxItems will be non-negative integers.
  • The products array can be empty.

Examples

1

Example 1

Input:

products = [{price: 10, beautyScore: 60}, {price: 20, beautyScore: 100}, {price: 30, beautyScore: 120}], maxBudget = 50, maxItems = 2

Output:

220

Note:

Select products with prices 20 and 30. Total price = 50, total items = 2, total beauty score = 100 + 120 = 220. Other combinations like (10, 20) give 160, (10, 30) give 180. Selecting all three exceeds maxItems.

2

Example 2

Input:

products = [{price: 5, beautyScore: 10}, {price: 8, beautyScore: 12}, {price: 3, beautyScore: 5}], maxBudget = 10, maxItems = 1

Output:

12

Note:

Only one item can be selected. The product with price 8 and beauty score 12 gives the maximum beauty score within budget.

3

Example 3

Input:

products = [{price: 100, beautyScore: 500}], maxBudget = 50, maxItems = 1

Output:

0

Note:

The only product exceeds the maxBudget, so no products can be selected.

Constraints

Constraints & assumptions

  • 1 <= products.length <= 100
  • 0 <= products[i].price <= 100
  • 0 <= products[i].beautyScore <= 1000
  • 0 <= maxBudget <= 1000
  • 0 <= maxItems <= 100

What interviewers evaluate

  • Correctness: The solution must correctly calculate the maximum beauty score for all valid inputs and edge cases.
  • Algorithm Design: Demonstrates understanding and application of Dynamic Programming, specifically a multi-dimensional knapsack variant.
  • Time & Space Complexity: Analyzes and optimizes the solution's performance to meet typical constraints for medium-difficulty problems.
  • Code Quality: Writes clean, readable, and well-structured code with appropriate variable names and comments where necessary.

Loading editor...