Smallest Element in Array

Practice this coding question on Coding Gurukul.

Problem statement

A freezer logs a sequence of temperature readings during a delivery. The inspection report needs the coldest recorded value, regardless of when it occurred. Your task Find the smallest element in the given array. Important details Readings may be negative, zero, or repeated. Return the minimum value rather than its index. A single reading is its own minimum. Initialize your comparison using an actual reading so that an all-positive or all-negative log is handled correctly. A single O(n) scan is sufficient. Worked example For readings 8, -3, 5, -3, the coldest value is -3. It is printed once even though it appears twice.

Input format

The first line contains n. The second line contains n integers.

Output format

Print the minimum value.

Constraints

1 <= n <= 100000; -1000000000 <= a[i] <= 1000000000.

Sample input

4
8 -3 5 -3

Sample output

-3

Sign in to run or submit a solution in C++, Java or Python.

Loading Coding Gurukul…