All challenges
Easy 0 solved 0% acceptance

Largest of Three

Pick the largest of three numbers without a built-in max.

What you'll learn

  • Compare values without a built-in max
  • Combine conditions with and
  • Handle equal values

Problem

Return the largest of three integers. Practice comparisons with if statements; don't use a built-in max function.

Implement largest_of_three(a, b, c).

Input

a: The first number. b: The second number. c: The third number.

Output

Return the largest value.

Constraints

-1,000,000,000 ≤ a, b, c ≤ 1,000,000,000

Examples

Example 1
Input:
a = 3
b = 9
c = 4

Expected output:
expected = 9
Input:
long long a = 3;
long long b = 9;
long long c = 4;

Expected output:
long long expected = 9;
Input:
long a = 3;
long b = 9;
long c = 4;

Expected output:
long expected = 9;

Explanation

9 is greater than both 3 and 4.

Example 2
Input:
a = -5
b = -2
c = -2

Expected output:
expected = -2
Input:
long long a = -5;
long long b = -2;
long long c = -2;

Expected output:
long long expected = -2;
Input:
long a = -5;
long b = -2;
long c = -2;

Expected output:
long expected = -2;

Explanation

-2 appears twice and is the largest value.

How to approach it

Try on your own first, then open one hint at a time.

Hint 1

Compare the numbers pair by pair to identify the largest one.

Hint 2

A few conditional checks are enough; no search structure is needed.

Hint 3

Be careful with equal values, since ties should still return the correct largest number.

Expected complexity

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

References

This challenge is adapted for CodeUtility. Follow the statement and constraints above.

Learn from others

Community solutions

No published solutions yet. Solve this challenge to share the first one.