Todos os desafios
Fácil 0 resolvidos 0% de aceitação

Smallest of Three

Return the smallest of three integers.

O que você vai aprender

  • Keep track of the best value so far
  • Compare values with if statements
  • Handle ties and negative numbers

Problema

Ver tradução

Three friends compare how many minutes they were late this week and the one who was late the least gets to pick lunch. Given the three numbers, find the smallest. Some values can be equal, and they can be negative (early).

Implement smallest_of_three(a, b, c).

Input

a: The first number.

b: The second number.

c: The third number.

Output

Return the smallest of the three values. If several are equal and smallest, return that value.

Restrições

−10^18 ≤ a, b, c ≤ 10^18

Exemplos

Exemplo 1
Entrada:
a = 7
b = 15
c = 3

Saída esperada:
expected = 3
Entrada:
long long a = 7;
long long b = 15;
long long c = 3;

Saída esperada:
long long expected = 3;
Entrada:
long a = 7;
long b = 15;
long c = 3;

Saída esperada:
long expected = 3;

Explicação

3 is less than both 7 and 15.

Exemplo 2
Entrada:
a = -4
b = -4
c = 10

Saída esperada:
expected = -4
Entrada:
long long a = -4;
long long b = -4;
long long c = 10;

Saída esperada:
long long expected = -4;
Entrada:
long a = -4;
long b = -4;
long c = 10;

Saída esperada:
long expected = -4;

Explicação

The two −4 values tie for smallest, so the answer is −4.

Como abordar

Tente sozinho primeiro e depois abra uma dica de cada vez.

Dica 1

Assume the first number is the smallest.

Dica 2

Compare it with the second and then the third, updating when you find a smaller one.

Dica 3

Use a 64-bit integer type, the values can be very large.

Complexidade esperada

O(1) time, O(1) extra space

Referências

Este desafio foi adaptado para o CodeUtility. Siga o enunciado e as restrições acima.

A melhor solução aprovada de cada programador. As mais rápidas, leves e mais bem avaliadas ficam no topo.

Ainda não há soluções aprovadas. Resolva e fique com o primeiro lugar.

Aprenda com outros

Soluções da comunidade

Ainda não há soluções publicadas. Resolva este desafio para compartilhar a primeira.