Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Removed Redundant code: 8 lines of Code.

k

Jul 15, 2023

def solve_knapsack(self, profits, weights, capacity):     n = len(profits)     dp = [0] * (capacity + 1)     for i in range(n):         for j in range(capacity, weights[i] - 1, -1):             dp[j] = max(profits[i] + dp[j - weights[i]], dp[j])     return dp[capacity]     return -1

1

0

Comments
Comments

On this page