PROBLEM 39
Easy

Different Signs

Programming Basics · JavaScript

</>
STATUS Not solved

TASK

Problem

#39

Given two non-zero integers `a`, `b`, print `YES` if their signs differ, else `NO`.

EXAMPLE

Example

Input
4 -9
Output
YES

LIMITS

Constraints

a ≠ 0; b ≠ 0
📖
LEARN Theory for this problem
+

### Different Signs

`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 [a, b] = input.trim().split(/\s+/).filter(Boolean).map(Number);
if (((a > 0) && (b < 0)) || ((a < 0) && (b > 0))) {
    console.log("YES");
} else {
    console.log("NO");
}