Feature Release Planner
As a product manager leading a software development team, you're tasked with planning the next release. Your goal is to deliver the maximum variety of features to customers, represented by distinct feature categories, while staying within a strict development budget. A key challenge is that some feature categories have prerequisites: certain other categories must be present in the release for features from a dependent category to be considered.
This problem requires you to optimize feature selection to maximize customer value (distinct categories) under financial and logical constraints, mirroring real-world product planning.
Implement the maximizeDistinctFeatureCategories function that determines the maximum number of distinct feature categories that can be included in a release, given a list of available features and a total budget.
Your solution must:
Input:
features: An array of Feature objects. Each Feature object has the following structure:
id: string - A unique identifier for the feature.cost: number - The development cost of this feature.category: string - The category this feature belongs to.prerequisites: string[] - An array of category names that must be present in the release for this feature to be considered.budget: number - The total development budget available.Output:
number - The maximum number of distinct feature categories that can be included in the release, adhering to the budget and all prerequisite rules.features array is empty or no features can be acquired within the budget, return 0.Examples
Example 1
Input:
features = [ { id: "F1", cost: 10, category: "UI", prerequisites: [] }, { id: "F2", cost: 20, category: "Backend", prerequisites: [] }, { id: "F3", cost: 15, category: "Analytics", prerequisites: ["Backend"] } ], budget = 30
Output:
2
Note:
Categories: UI, Backend, Analytics. Mapped to 0, 1, 2.
Within budget 30:
Example 2
Input:
features = [ { id: "F_CORE", cost: 5, category: "Core", prerequisites: [] }, { id: "F_ADV", cost: 10, category: "Advanced", prerequisites: ["Core"] }, { id: "F_UTIL", cost: 8, category: "Utility", prerequisites: [] } ], budget = 15
Output:
2
Note:
Categories: Core, Advanced, Utility. Mapped to 0, 1, 2.
Within budget 15:
Example 3
Input:
features = [ { id: "F1", cost: 100, category: "UI", prerequisites: [] } ], budget = 50
Output:
0
Note:
The only feature F1 costs 100, which exceeds the budget of 50. No features can be selected, resulting in 0 distinct categories.
Constraints
1 <= features.length <= 501 <= budget <= 10001 <= feature.cost <= 100feature.category is a string with 1 <= category.length <= 20.1 and 15 (inclusive). This constraint is critical for bitmasking approaches.feature.prerequisites: An array of category strings. 0 <= prerequisites.length <= 5. All prerequisite category strings will be valid categories present in at least one feature.Loading editor...