#996

Number of Squareful Arrays

candidate master · 1395 · lc hard +32 · verified · 51.2% accepted · 1,037 likes · top 40%

Description

An array is squareful if the sum of every consecutive pair of elements is a perfect square.

Given an integer array nums, return the total count of permutations of nums that are squareful.

Two permutations perm1 and perm2 differ if there exists some index i where 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

Code

1
2
3