|
U
Pro3. Find Largest of Three Integers
Easy
Problem Description
Given three integers A, B, and C, find and print the largest value among them without using built-in array sorting.
Input Format
A single line containing three space-separated integers A, B, and C.
Output Format
Print the single maximum integer value.
Example 1:
Input:
5 12 9
Output:
12
Explanation: Comparing 5, 12, and 9: 12 is greater than both 5 and 9.
Example 2:
Input:
-3 -8 -1
Output:
-1
Explanation: Among negative integers, -1 is closest to zero and thus the largest.
Example 3:
Input:
7 7 7
Output:
7
Explanation: All three integers are equal, so the maximum is 7.
Constraints:
-10^9 <= A, B, C <= 10^9Time complexity target: O(1)Auxiliary space target: O(1)
Follow up:How would you scale this to find the maximum of N streaming numbers with O(1) memory?
1,180 Online
Code
|Loading Code Editor...
SavedLn 1, Col 1
input =
Sandboxed Engine
Ctrl+Enter = Run | Ctrl+Shift+Enter = Submit