703496. Equalization of an array

Easy

Equalization of an Array

Slug: equalization-of-an-array1656

Difficulty: Easy

Id: 703496

Topic Tags: Arrays, Data Structures

Company Tags: None

Summary

The problem is about equalizing an array where all elements are less than or equal to a certain value. The task is to find the maximum possible value that can be used for equalization.

Detailed Explanation

To solve this problem, we need to iterate through the array and update the maximum possible value for equalization. We start by initializing our maximum possible value as the first element of the array. Then, we iterate through the rest of the array. For each element, if it is greater than our current maximum possible value, we update our maximum possible value.

Here's a step-by-step breakdown:

  1. Initialize max_value to the first element of the array.
  2. Iterate through the array starting from the second element.
  3. For each element, check if it is greater than max_value. If yes, update max_value.
  4. After iterating through the entire array, max_value will be the maximum possible value for equalization.

Time complexity: O(n), where n is the size of the array. Space complexity: O(1).

Optimized Solutions

Java

View on GeeksforGeeks
public class Main {
    public static int equalizeArray(int[] arr) {
        int max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] > max) {
                max = arr[i];
            }
        }
        return max;
    }

    public static void main(String[] args) {
        int[] arr = {3, 6, 7, 8};
        System.out.println(equalizeArray(arr));
    }
}

DevExCode

Master coding interviews with Leetcode, system design, TechBit, QuickLearn, DevTips, Tech Battles, and career services.

© 2026 DevExCode. All rights reserved.