A photo wall is built from square thumbnails. A thumbnail of side k covers k * k cells, and any side length can be used any number of times. You need thumbnails whose areas add up to exactly n cells.
Write fewestSquares(n) that returns the fewest thumbnails needed.
Input: n = 18 Output: 2
9 + 9: two thumbnails of side 3.
Input: n = 7 Output: 4
4 + 1 + 1 + 1. No two or three squares add up to 7.
1 <= n <= 10000Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #521 Fewest Square Thumbnails. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.