Python Noções básicasFácil

Encontre o maior elemento em uma matriz

Guia detalhado e implementação de Python para o problema 'Encontrar o maior elemento em um array'.

Declaração do problema

Fácil

Escreva uma função find_largest(arr) que pegue uma lista de inteiros arr e retorne o maior elemento. Itere pela matriz e rastreie o valor máximo 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
8
Explanation

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

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

Among negative numbers, -1 is the largest.

Example 3
Input
arr = [100]
Output
100
Explanation

Only one element, so it is the largest.

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.