Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • \$\begingroup\$ Doing this in a lambda could make it shorter. \$\endgroup\$ Commented May 8, 2017 at 19:11
  • \$\begingroup\$ @Okx It is recursive (so it would be longer), plus I don't do lambdas even if they would be shorter. \$\endgroup\$ Commented May 8, 2017 at 19:14
  • 1
    \$\begingroup\$ The iterative version of your algorithm is way shorter as you remove the need to copy the array: boolean f(int[]c,int n){for(int l=c.length;l-->0;n-=n<c[l]?0:c[l]);return n<1;} (79 bytes). With Java 8 and its lambdas, it can further be reduced to 62 bytes. Regarding your answer as it currently is, int l=c.length-1 then using l instead of l-1 is also shorter. \$\endgroup\$ Commented May 9, 2017 at 13:30