Zero-one knapsack: Given equal-length weights and values arrays and a capacity, return the maximum total value obtainable when every item may be selected at most once.
Input: A JSON object { "weights": number[], "values": number[], "capacity": number }.
Output: A JSON number containing the maximum value.
Constraints:
- 0 <= weights.length = values.length <= 1000
- Weights are positive integers
- capacity is a non-negative integer
Read one JSON value from stdin and print exactly one JSON-serialized answer to stdout with no extra text.
Difficulty: EASY. Variant: 4. Balance correctness, maintainability, and clear review-ready code.
Practice context
This coding (algo) exercise trains prompt interpretation, explicit assumptions, a concrete response, and a concise explanation of the decisions made. It is marked easy difficulty.
The signed-in workspace provides the tools required by