Skip to main content
Back to problems
Leetcode
Medium
Arrays
Sorting
Math
Google
Transform Array To All Equal Elements

Determine whether an array can be transformed so all elements become equal, and identify the minimum effort required under the problem's allowed operations.

Acceptance 100%
Problem Statement

Given an integer array, you may apply the operation(s) described by the problem to transform the array. Your task is to determine whether it is possible to make every element of the array equal. If it is possible, compute the minimum number of operations needed according to the allowed transformation rules.

This is an array equalization problem: you are looking for a target value that all elements can be converted to, while respecting the operation constraints and minimizing total work.

Input Format

Input

  • An integer array nums.
  • The exact operation rules are defined by the problem statement on the platform.

Assumption for practice version

  • nums contains at least one integer.
  • All operations act on array elements only.

Output Format

Output

  • Return whether the array can be transformed so that all values are equal.
  • If the transformation is possible, also return the minimum number of operations required according to the allowed rules.

Constraints

  • Array size and value ranges depend on the original platform problem.
  • A correct solution should be efficient enough for standard interview-sized inputs.
  • Be careful about parity, reachability, or target-selection conditions implied by the operation rules.
Examples
Sample cases returned by the problem API.

Example 1

Input

nums = [1, 2, 3]

Output

possible = true, minOperations = 2

Explanation

A representative equalization process reaches a common value in the minimum number of allowed steps. The exact steps depend on the operation rules, but the key idea is to choose a feasible target and minimize total work.

Example 2

Input

nums = [4, 4, 4]

Output

possible = true, minOperations = 0

Explanation

All elements are already equal, so no operations are needed.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.