700333. Find Maximum value

Easy

Here is a detailed Markdown blog post for the problem "Find Maximum value":

Find Maximum Value

Summary

In this problem, we are given an array of integers and asked to find the maximum value in it. This problem involves basic algorithmic concepts such as arrays and comparison operations.

Detailed Explanation

To solve this problem, we can use a simple linear scan through the array. We initialize our maximum value to the first element in the array, then iterate through the rest of the array, updating our maximum value whenever we find a larger one.

Here is a step-by-step breakdown of the solution:

  1. Initialize max to the first element in the array.
  2. Iterate through the rest of the array.
  3. For each element, compare it to max. If it's greater, update max.
  4. Return max.

This algorithm has a time complexity of O(n), where n is the number of elements in the array, since we need to scan through all elements at least once. The space complexity is O(1) since we only use a constant amount of space.

Optimized Solutions

Java

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

DevExCode

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

© 2026 DevExCode. All rights reserved.