PROBLEM 49
Medium

Maximum of Three

Programming Basics · JavaScript

</>
STATUS Not solved

TASK

Problem

#49

Given three integers, find the maximum without using `Math.max()`.

EXAMPLE

Example

Input
4 9 2
Output
9

LIMITS

Constraints

All numeric input values fit in JavaScript `Number`.
📖
LEARN Theory for this problem
+

### Maximum of Three

`if / else if / else` chooses a branch from boolean conditions. Comparisons such as `<`, `>=`, `===` and logical operators `&&`, `||`, `!` combine the exact rules that decide which output is valid.

💡
NEED HELP? Hints
+

['Translate every case from the statement into a boolean condition before writing branches.', 'Order the checks so a more specific case is not swallowed by a broader condition.']

ANSWER Solution
+
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trimEnd();
let [a, b, c] = input.trim().split(/\s+/).filter(Boolean).map(Number);
let m = a;
if (b > m) {
    m = b;
}
if (c > m) {
    m = c;
}
console.log(m);