Subset Sum - MATLAB Cody - MATLAB Central

Problem 43. Subset Sum

Difficulty:Rate

Given a vector v of integers and an integer n, return the the indices of v (as a row vector in ascending order) that sum to n. If there is no subset in v that sums to n, return an empty matrix []. You can assume that the answer will always be unique.

Example:

 >> v = [2, 3, 5];
 >> n = 8;
 >> subset_sum(v, n)
 ans =
      2     3

Solution Stats

41.91% Correct | 58.09% Incorrect
Last Solution submitted on May 09, 2025

Problem Comments

Solution Comments

Show comments
LLMs with MATLAB updated to support the latest OpenAI Models
Large Languge model with MATLAB, a free add-on that lets you access...
2
4

Problem Recent Solvers1953

Suggested Problems

More from this Author96

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Go to top of page