Tap here to switch tabs
Problem
Submissions

Problem: Longest Square Streak in an Array

med
30 min
Try to solve the Longest Square Streak in an Array problem.

Statement

You are given an integer array nums. A subsequence of nums is called a square streak if:

  • The length of the subsequence is at least 22.

  • After sorting the subsequence in strictly ascending order, each element after the first is equal to the square of the preceding element.

Return the maximum length of a square streak in nums, or return −1-1 if no square streak exists.

Constraints:

  • 2≤2 \leq nums.length ≤105\leq 10^5

  • 2≤2 \leq nums[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Longest Square Streak in an Array

med
30 min
Try to solve the Longest Square Streak in an Array problem.

Statement

You are given an integer array nums. A subsequence of nums is called a square streak if:

  • The length of the subsequence is at least 22.

  • After sorting the subsequence in strictly ascending order, each element after the first is equal to the square of the preceding element.

Return the maximum length of a square streak in nums, or return −1-1 if no square streak exists.

Constraints:

  • 2≤2 \leq nums.length ≤105\leq 10^5

  • 2≤2 \leq nums[i] ≤105\leq 10^5