Python BasicsEasy

Find Smallest Element in an Array

Detailed guide and Python implementation for the 'Find Smallest Element in an Array' problem.

Problem Statement

Easy

Write a function find_smallest(arr) that takes a list of integers arr and returns the smallest element. Iterate through the array and track the minimum value seen so far.

Constraints
  • 1 <= len(arr) <= 10^5
  • -10^9 <= arr[i] <= 10^9

Examples

Example 1
Input
arr = [3, 7, 2, 8, 1]
Output
1
Explanation

Comparing all elements: 3, 7, 2, 8, 1. The minimum is 1.

Example 2
Input
arr = [-5, -2, -8, -1]
Output
-8
Explanation

Among negative numbers, -8 is the smallest.

Example 3
Input
arr = [42]
Output
42
Explanation

Only one element, so it is the smallest.

Need a Hint?
Consider using Arrays-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.