Talentd
FleetCode

996. Number of Squareful Arrays

Hard51.9% acceptance2 companies

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 <= 12
  • 0 <= nums[i] <= 109

Asked at 2 companies

14:40
Still stuck?Read 3 approaches, or watch a walkthrough.
Open solution

Similar problems

Permutations IIMedium
Loading editor…
1class Solution:
2 def numSquarefulPerms(self, nums: List[int]) -> int:
3
Starter codePython 3Spaces: 4
Examples
Input
[1,17,8]
Input
[2,2,2]
Your code is saved on this device.Solution