Perfect Squares 2

Prereq: Knapsack Intro

This problem is similar to Perfect Squares, except a number can only be used once. Again we ask you to output the minimum number of numbers in order to sum to the desired number. Output -1 if the number can't be reached.


Example 1:
Input: 12
Output: -1

You cannot make 12 with any combination of 1, 4, 9

Example 2:
Input: 13
Output: 2

13 = 4 + 9

Try it yourself




Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

Contrary to popular belief, Lorem Ipsum is not simply random text.

1  >>> a = [1, 2, 3]
2  >>> a[-1]
3  3

Get premium for instant access to all content and solutions