Number of Squareful Arrays

Given an array of integers A, the array is squareful if for every pair of adjacent elements,
their sum is a perfect square.

Find and return the number of permutations of A that are squareful. Two permutations A1 and A2 differ
if and only if there is some index i such that A1[ i ] != A2[ i ].



Input Format

The only argument given is the integer array A.

Output Format

Return the number of permutations of A that are squareful.

Constraints

1 <= length of the array <= 12
1 <= A[i] <= 10^9 

For Example

Input 1:
    A = [2, 2, 2]
Output 1:
    1

Input 2:
    A = [1, 17, 8]
Output 2:
    2
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Number of Squareful Arrays on Interview Code Editor
Sign Up
to access hints and editorial solutions for Number of Squareful Arrays

Discussion


Loading...
Click here to start solving coding interview questions