arrays - Remove a group of integers from the list if all but one equals the remaining number until one is left -


we start list of integers. can remove group of integers list if 1 equals remaining number. removal operation can performed in remaining number of list until no more operations can performed.

write function can accept array of integers, , return minimal number of remaining integers performing operation.

example [1, 3, 5, 6] -> remove 1, 5, 6 , because 1 + 5 = 6, [3] left, return 1

[48, 20, 1, 3, 4, 6, 9, 24] -> remove 3, 6, 9 , because 3 + 6 = 9, , remove 4, 20, 24, 48, because 4 + 20 + 24 + 48, [1] left, return 1

int left(int[] nums){  } 

a facebook interview question https://www.careercup.com/question?id=5191669463908352.

i considered generating sum permutations, removing numbers matched, , repeatedly generating sum permutations remaining numbers until nothing can removed. that's inefficient. there more efficient way this?


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -