## Amazon interview question

1 Answer

| Flag | PURGE

**Amazon interview question**Print all subset of a given set which sums up to ZERO

{8,3,5,1,-4,-8}

so ans will be : {8,-8}

{3,5,-8}

{3,1,-4}

size of set can be upto 50 but elemet of set can be as big as 18 digit number

Email me when people comment.

Email me when people comment.

Loading...

An error occurred in subscribing you.

Email me when people comment.

Email me when people comment.

Loading...

An error occurred in subscribing you.

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window

Get all sub-sets of the questions set [which can be can have as many as (2^sizeOfSet)-1 elements].

int maxNumOfSubsets = (2^set.size())-1

Getting all sub-sets can be done by using the binary representation of all integers between 1 and maxNumOfSubsets.

The simply sum each sub-set, if the sum is zero then you have an answer.

- Justin February 15, 2015