Funcia
Tutorialmath

The Larger of Two

Memory limit
256 MB
Correctness time limit
10000 ms
Solvers
0
0

Given two integers a and b, return the larger one. If they are equal, return that value.

Examples

abresult
377
-2-9-2
555

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

  • −109≤-10^9 \le a, b ≤109\le 10^9

Expected complexity

Time
O(1)
Space
O(1)

Examples

abExpected
377
-2-9-2
555

Hint

Hint

Compare with if: return a when a > b, otherwise b. Most languages also have a built-in max.

Time limits per language

LanguageEfficiency time limit
C (GCC, gnu17)200 msestimated
C++ (GCC, gnu++23)200 msderived
Python 3.131000 msderived
Java 251000 msderived
Kotlin 2.4 (JVM)1200 msestimated
C# 14 (.NET 10)1200 msestimated

Test groups

GroupWeightTestsVisibility
sample03inputs and outputs
correctness10012verdict only
Loading editor…
Log in to run or submit code.

No result yet. Run or submit your code.