Tap here to switch tabs
Problem
Submissions

Problem: Find the Maximum Number of Elements in Subset

Find the Maximum Number of Elements in Subset asks you to select a subsequence of positive integers forming powers of one integer that rise to a peak and mirror back, maximizing its length.

Statement

You are given an array of positive integers nums.

You need to select a subset of nums that can be arranged into a sequence of length 2k+12k + 1 for some integer k≥0k \ge 0, such that the sequence follows the pattern:

[x,x2,x4,…,x2k,…,x4,x2,x][x, x^2, x^4, \dots, x^{2^k}, \dots, x^4, x^2, x]

for some positive integer xx.

Return the maximum number of elements in such a subset.

Note: A subset is a collection of elements obtained by deleting zero or more elements from an array without changing the relative order of the remaining elements.

Constraints:

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

  • 1≤1 \leq nums[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find the Maximum Number of Elements in Subset

Find the Maximum Number of Elements in Subset asks you to select a subsequence of positive integers forming powers of one integer that rise to a peak and mirror back, maximizing its length.

Statement

You are given an array of positive integers nums.

You need to select a subset of nums that can be arranged into a sequence of length 2k+12k + 1 for some integer k≥0k \ge 0, such that the sequence follows the pattern:

[x,x2,x4,…,x2k,…,x4,x2,x][x, x^2, x^4, \dots, x^{2^k}, \dots, x^4, x^2, x]

for some positive integer xx.

Return the maximum number of elements in such a subset.

Note: A subset is a collection of elements obtained by deleting zero or more elements from an array without changing the relative order of the remaining elements.

Constraints:

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

  • 1≤1 \leq nums[i] ≤109\leq 10^9