01
02
03
04
05
06
07
08
09
10
11
A
A2Z Sheet

3. Decision Branching & The Balance Scale

Easy
Step 1: Learn the basics›Things to Know in C++/Java/Python or any language

Decision Branching & The Balance Scale

EasyFunction: ifElseif()
ASCI Mission Breakdown • Simple as Hell
"Compare two weights and state whether the first is smaller, greater, or equal to the second."
Real-World Metaphor:

Imagine a physical seesaw at a playground. If child A is lighter than child B, child A goes up ("smaller"). If heavier, child A drops down ("greater"). If they weigh exactly the same, the seesaw rests in balance ("equal").

Interactive Visual WalkthroughFLOW-DIAGRAM
Step 1 / 3
Left (a)5
Right (b)9
Evaluating

1. Place Weights on Scale

Inspect inputs: Left pan a = 5, Right pan b = 9.

How to Think About This (Mental Model)

  1. Check if a < b: if true, immediately return "smaller".
  2. Check if a > b: if true, immediately return "greater".
  3. If neither condition triggered, they must be identical, so return "equal".

### The Mission You are the official arbiter of a two-pan balance scale. Two contestants place their weights onto the scale: weight **a** on the left pan, and weight **b** on the right pan. Your job is to compare them and announce one of three verdicts: - Return **"smaller"** if `a < b` (the left pan is lighter). - Return **"greater"** if `a > b` (the left pan is heavier). - Return **"equal"** if `a === b` (both pans balance perfectly).

Examples

Example 1
Input: x = 10, y = 20
Output: 30
Explanation: Returns the processed result of the inputs.

Constraints

  • -10^5 <= x, y <= 10^5
Topic Tags:
Learn the basicsThings to Know in C++/Java/Python or any languageifElseif
14px
Ln 1:Col 1
9 lines•126 chars
Spaces: 2•UTF-8
JS(Node v20.12)