A layout engine can nest grids: a page of n tiles might be 2 groups of 6, or 2 groups of 2 groups of 3. Each nesting is a way to write n as a product of two or more whole numbers, each at least 2.
Write factorLayouts(n) that returns every such product as an array of factors in non-decreasing order. List the arrays in sorted order: compare first factors, then second factors, and so on.
If n can't be written this way (for example 1 or a prime), return [].
Input: n = 12 Output: [[2,2,3],[2,6],[3,4]]
12 = 2 × 2 × 3 = 2 × 6 = 3 × 4. 12 alone doesn't count, since it needs two or more factors.
Input: n = 7 Output: []
7 is prime, so it can't be split into smaller factors.
1 <= n <= 10^6Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #306 Factor Grid Layouts. 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.