id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

norm.krumpe@muohio.edu arrays > cantMakeIt
prev  |  next  |  chance

Given the array {7, 5, 1, 2, 3, 1}, it has many "subarrays" such as {5, 1, 2}, and {2, 3}, and {7}, and even {7, 5, 1, 2, 3, 1} (an array is a subarray of itself). If you look carefully, you can find a subarray whose elements add up to 1, a subarray whose elements add up to 2, a subarray whose elements add up to 3. In fact, with the array {7, 5, 1, 2, 3, 1}, you can find subarrays whose elements total 1, 2, 3, 4, 5, 6, 7, and 8, but you cannot find a subarray whose elements total 9. Given an array, find the smallest positive integer that cannot be obtained by adding together the elements in one of its subarrays.


cantMakeIt([7, 5, 1, 2, 3, 1]) → 9
cantMakeIt([4, 3]) → 1
cantMakeIt([1, 2, 3, 4]) → 8

...Save, Compile, Run (ctrl-enter)

int cantMakeIt(int[] nums) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 300

Copyright Nick Parlante 2017 - privacy