Number in Range
Programming Basics · JavaScript
TASK
Problem
Given `n`, `left`, `right` with `left ≤ right`, print `YES` if `n` lies in `[left, right]`, else `NO`.
EXAMPLE
Example
7 5 10
YES
LIMITS
Constraints
left ≤ right
LEARN
Theory for this problem
+
### Number in Range
`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.', 'Check values exactly on the condition boundary: `=`, `<`, and `>` must match the statement without an off-by-one shift.']
ANSWER
Solution
+
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trimEnd();
let [n, left, right] = input.trim().split(/\s+/).filter(Boolean).map(Number);
if ((left <= n) && (n <= right)) {
console.log("YES");
} else {
console.log("NO");
}