Frontend School

Software Feature Prioritization

DSA
medium

Software Feature Prioritization

Medium
Dynamic Programming
Knapsack
Algorithms

Overview

In agile software development, product managers often face the challenge of prioritizing features given limited resources. Each feature requires a certain amount of development effort (cost) and consumes system resources (size). The goal is to maximize the number of features delivered while staying within budget and system capacity.

What you need to do / Task

You are tasked with implementing a function maximizeFeatures that helps a product manager determine the maximum number of features that can be implemented. You are given a list of features, each with an associated size and cost, along with a maxSize (total system resource capacity) and maxCost (total development budget).

Input & output

maximizeFeatures(features, maxSize, maxCost)

  • features: Feature[] - An array of objects, where each object represents a feature and has the following properties:
    • size: number - The system resource consumption for this feature (e.g., memory, disk space).
    • cost: number - The development effort/cost for this feature.
  • maxSize: number - The maximum total system resource capacity available.
  • maxCost: number - The maximum total development budget available.

Returns: number - The maximum number of features that can be implemented within the given maxSize and maxCost constraints.

Clarifications

  • All size and cost values for features, maxSize, and maxCost will be positive integers.
  • If no features can be selected within the given constraints, the function should return 0.
  • Features are distinct and cannot be selected multiple times (this is a 0/1 Knapsack problem variant).

Examples

1

Example 1

Input:

features = [{size: 2, cost: 3}, {size: 3, cost: 4}, {size: 4, cost: 5}], maxSize = 5, maxCost = 7

Output:

2

Note:

To maximize features, we can select {size: 2, cost: 3} and {size: 3, cost: 4}. Their total size is 5 (<= 5) and total cost is 7 (<= 7). This gives 2 features. No other combination yields more than 2 features within limits.

2

Example 2

Input:

features = [{size: 10, cost: 10}, {size: 20, cost: 20}], maxSize = 5, maxCost = 5

Output:

0

Note:

Neither feature can be selected individually as their size or cost exceeds the given maximums. Thus, 0 features can be implemented.

3

Example 3

Input:

features = [{size: 1, cost: 10}, {size: 2, cost: 1}, {size: 3, cost: 2}], maxSize = 3, maxCost = 12

Output:

2

Note:

Selecting {size: 1, cost: 10} and {size: 2, cost: 1} results in a total size of 3 (<= 3) and total cost of 11 (<= 12). This provides 2 features. Other combinations either exceed size/cost or yield fewer features.

Constraints

Constraints & assumptions

  • 1 <= features.length <= 100
  • 1 <= feature.size <= 1000
  • 1 <= feature.cost <= 1000
  • 1 <= maxSize <= 10000
  • 1 <= maxCost <= 10000
  • All input values are non-negative integers.

Out of scope

  • Error handling for invalid input types or negative values.
  • Optimizing for execution speed beyond typical dynamic programming approaches (e.g., highly specialized data structures for sparse DP tables).

What interviewers evaluate

  • Correct identification and application of a dynamic programming strategy.
  • Accurate definition of the DP state and transition logic for a multi-dimensional knapsack problem.
  • Optimal time and space complexity given the constraints.
  • Clarity, readability, and maintainability of the code.

Loading editor...