Skip to content

Practice Find the Maximum Number of Elements in Subset

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3020
LeetCode Problem

Find the Maximum Number of Elements in Subset

Problem Statement

Select as many occurrences from nums as possible so that they can be arranged as an odd-length sequence whose values start at some x, repeatedly square until the central value, and then retrace the preceding values in reverse order. For example, [2, 4, 16, 4, 2] is valid, but [2, 4, 8, 4, 2] is not. A single selected value is also valid. Each occurrence can be used at most as many times as it appears in nums. Return the maximum number selected.

Source: Find the Maximum Number of Elements in Subset on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [5,4,1,2,2]
Output
3

# Example 2

Input
nums = [1,3,2,4]
Output
1

Constraints

2 <= nums.length <= 10^5
1 <= nums[i] <= 10^9

Related LeetCode Problems

Practice more problems similar to Find the Maximum Number of Elements in Subset.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.