Back to Practice Dashboard
Python BasicsEasy
Greatest of two numbers
Learn how to solve the 'Greatest of two numbers' problem. This detailed resource details brute force and optimized approaches.
Problem Statement
Easy
Write a function greatest_of_two(a, b) that takes two integers a and b and returns the greater of the two. If both are equal, return that value.
Constraints
- •-10^9 <= a, b <= 10^9
Examples
Example 1
Input
a = 10, b = 20
Output
20
Explanation
20 > 10, so 20 is the greatest.
Example 2
Input
a = 7, b = 3
Output
7
Explanation
7 > 3, so 7 is the greatest.
Example 3
Input
a = 5, b = 5
Output
5
Explanation
Both are equal, so return 5.
Need a Hint?
Use simple arithmetic operators (like modulo `%`, division `//`), conditional checks, or loops to inspect number properties.
Edge Cases to Watch
- Empty list or null input variables
- Single item lists/arrays
- Extremely large input bounds causing integer or stack overflow
Ready to Solve?
Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.