Problem 660. Find a subset that divides the vector into equal halves
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
Problem Comments
-
14 Comments
Show
11 older comments
Hassan Dehghani
on 7 Apr 2014
why do i get internal server error :(((
Ned Gulley
on 8 Apr 2014
Hassan, where are you getting an internal server error? Maybe leave your comment on the solution that has the related error? I'm guessing that your solution relies on randomness, so if you don't get lucky, the answer will time out. You may get lucky on your computer, but not on the Cody server.
John D'Errico
on 22 Aug 2016
A basic one liner with intlinprog, but not an option in Cody. :)
Solution Comments
Show commentsGroup

ASEE Challenge
- 10 Problems
- 250 Finishers
- Find the biggest empty box
- How long is the longest prime diagonal?
- Flag largest magnitude swings as they occur
- Solitaire Cipher
- Spot the outlier
- How long is the longest prime diagonal?
- Solitaire Cipher
- Implement simple rotation cypher
- Given a window, how many subsets of a vector sum positive
- How many trades represent all the profit?
- Flag largest magnitude swings as they occur
- Make a run-length companion vector
- Spot the outlier
- Find a subset that divides the vector into equal halves
- How long is the longest prime diagonal?
- Find the biggest empty box
Problem Recent Solvers391
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!