Python Noções básicasFácil

Encontre o menor elemento em uma matriz

Guia detalhado e implementação de Python para o problema 'Encontrar o menor elemento em uma matriz'.

Declaração do problema

Fácil

Escreva uma função find_smallest(arr) que pegue uma lista de inteiros arr e retorne o menor elemento. Itere pela matriz e rastreie o valor mínimo visto até agora.

Restrições
  • 1 <= len(arr) <= 10^5
  • -10^9 <= arr[i] <= 10^9

Exemplos

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?
Considere usar estruturas de dados específicas de arrays, como conjuntos ou heaps.
Edge Cases to Watch
  • Estruturas de entrada vazias
  • Entradas de elemento único
  • Grandes limites numéricos

Pronto para resolver?

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

Abrir no Editor
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

Recursos Python recomendados

Expanda seu conhecimento com tutoriais interativos relacionados, folhas de dicas e comparações de código.