Problème
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.
Contraintes
−10^18 ≤ a, b, c ≤ 10^18
Exemples
Entrée :
a = 7
b = 15
c = 3
Sortie attendue :
expected = 3
Entrée :
long long a = 7;
long long b = 15;
long long c = 3;
Sortie attendue :
long long expected = 3;
Entrée :
long a = 7;
long b = 15;
long c = 3;
Sortie attendue :
long expected = 3;
Explication
3 is less than both 7 and 15.
Entrée :
a = -4
b = -4
c = 10
Sortie attendue :
expected = -4
Entrée :
long long a = -4;
long long b = -4;
long long c = 10;
Sortie attendue :
long long expected = -4;
Entrée :
long a = -4;
long b = -4;
long c = 10;
Sortie attendue :
long expected = -4;
Explication
The two −4 values tie for smallest, so the answer is −4.
Comment l'aborder
Essayez d'abord seul, puis ouvrez les indices un par un.
Indice 1
Assume the first number is the smallest.
Indice 2
Compare it with the second and then the third, updating when you find a smaller one.
Indice 3
Use a 64-bit integer type, the values can be very large.
Complexité attendue
O(1) time, O(1) extra space
Références
Ce défi a été adapté pour CodeUtility. Suivez l'énoncé et les contraintes ci-dessus.