14. Find Minimum in Array

EasyArrayArray

Given an integer array nums, find and return the minimum element in the array.

You must solve it without using any built-in min functions.

Input: An integer array nums of length n.

Output: A single integer — the minimum element.

Examples

Example 1
Input: [3,1,4,1,5,9,2,6]
Output: 1
Explanation: Start min=3. 1<3→min=1. 4,1,5,9,2,6 — none less than 1. Return 1.
Example 2
Input: [-5,-1,-3,-2]
Output: -5
Explanation: Start min=-5. -1>-5, -3>-5, -2>-5 — min stays -5. Return -5.
Example 3
Input: [42]
Output: 42
Explanation: Single element is trivially the minimum. Return 42.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →