Find a subset that divides the vector into equal halves - MATLAB Cody - MATLAB Central

Problem 660. Find a subset that divides the vector into equal halves

Difficulty:Rate

Given a vector x, return the indices to elements that will sum to exactly half of the sum of all elements.

Example:

 Input  x  = [1 2 3 4 5 6 7]
 Output xi = [1 6 7]

because

 sum(x) = 28
 sum(x([1 6 7])) = 14

The answer is not necessarily unique and the order is unimportant. We will just test to make sure that sum(x)/2 is sum(x(xi))

Solution Stats

25.69% Correct | 74.31% Incorrect
Last Solution submitted on Apr 04, 2025

Problem Comments

Solution Comments

Show comments
PIVlab surpasses 100K all-time File Exchange downloads
During the past twelve months, PIVlab, a MATLAB Community Toolbox for particle...
4
8
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 Solvers391

Suggested Problems

More from this Author50

Problem Tags

Community Treasure Hunt

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

Start Hunting!