881849. Vector min_element

Easy

Vector min_element

Summary

Find the minimum element in a vector (or array) using the std::min_element algorithm provided by the Standard Template Library (STL). This problem requires understanding how to use STL algorithms effectively.

Detailed Explanation

The problem is straightforward: given a vector of integers, find the smallest element in it. We can achieve this using the std::min_element algorithm from the <algorithm> header file. Here's a step-by-step breakdown:

  1. Include the necessary header files: <vector> and <algorithm>.
  2. Use std::min_element to find the minimum element in the vector. This algorithm returns an iterator pointing to the smallest element.

Here's a code example:

View on GeeksforGeeks
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        int[] arr = {4, 2, 9, 6, 23, 12, 34, 0};
        int minVal = Arrays.stream(arr).min().getAsInt();
        System.out.println("Minimum element in the array is: " + minVal);
    }
}

DevExCode

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

© 2026 DevExCode. All rights reserved.