Watch 10 video solutions for Number of Squareful Arrays, a hard level problem involving Array, Hash Table, Math. This walkthrough by The Code Skool has 92,673 views views. Want to try solving it yourself? Practice on FleetCode or read the detailed text solution.
An array is squareful if the sum of every pair of adjacent elements is a perfect square.
Given an integer array nums, return the number of permutations of nums that are squareful.
Two permutations perm1 and perm2 are different if there is some index i such that perm1[i] != perm2[i].
Example 1:
Input: nums = [1,17,8] Output: 2 Explanation: [1,8,17] and [17,8,1] are the valid permutations.
Example 2:
Input: nums = [2,2,2] Output: 1
Constraints:
1 <= nums.length <= 120 <= nums[i] <= 109