Tutorialmath
The Larger of Two
- Memory limit
- 256 MB
- Correctness time limit
- 10000 ms
- Solvers
- 0
Given two integers a and b, return the larger one. If they are equal, return that value.
Examples
| a | b | result |
|---|---|---|
3 | 7 | 7 |
-2 | -9 | -2 |
5 | 5 | 5 |
Example 1 — 7 is larger than 3.
Example 2 — Among negatives, -2 is larger than -9.
Example 3 — Both are 5, so return 5.
This is a tutorial problem: there are no performance tests, just return the correct value.
Function signature
solution(a: int, b: int) → int
Constraints
-
a,b
Expected complexity
- Time
- O(1)
- Space
- O(1)
Examples
| a | b | Expected |
|---|---|---|
3 | 7 | 7 |
-2 | -9 | -2 |
5 | 5 | 5 |
Hint
Hint
Compare with if: return a when a > b, otherwise b. Most languages also have a built-in max.
Time limits per language
| Language | Efficiency time limit | |
|---|---|---|
| C (GCC, gnu17) | 200 ms | estimated |
| C++ (GCC, gnu++23) | 200 ms | derived |
| Python 3.13 | 1000 ms | derived |
| Java 25 | 1000 ms | derived |
| Kotlin 2.4 (JVM) | 1200 ms | estimated |
| C# 14 (.NET 10) | 1200 ms | estimated |
Test groups
| Group | Weight | Tests | Visibility |
|---|---|---|---|
| sample | 0 | 3 | inputs and outputs |
| correctness | 100 | 12 | verdict only |