Quadrant Finder - Problem

Given two coordinates x and y, determine which quadrant the point lies in, or if it's on an axis.

Quadrant Rules:

  • Quadrant I: x > 0 and y > 0
  • Quadrant II: x < 0 and y > 0
  • Quadrant III: x < 0 and y < 0
  • Quadrant IV: x > 0 and y < 0
  • On Axis: x = 0 or y = 0

Return the quadrant number (1, 2, 3, or 4) or the string "On Axis" if the point lies on an axis.

Input & Output

Example 1 — Quadrant IV
$ Input: x = 3, y = -2
Output: 4
💡 Note: Point (3, -2) has x > 0 and y < 0, which places it in Quadrant IV
Example 2 — Quadrant II
$ Input: x = -5, y = 7
Output: 2
💡 Note: Point (-5, 7) has x < 0 and y > 0, which places it in Quadrant II
Example 3 — On Axis
$ Input: x = 0, y = 5
Output: On Axis
💡 Note: Point (0, 5) lies on the y-axis since x = 0

Constraints

  • -109 ≤ x ≤ 109
  • -109 ≤ y ≤ 109

Visualization

Tap to expand
INPUTALGORITHMRESULTPoint Coordinatesx = 3y = -2Coordinate plane positionto be classified1Check if on axisx = 0 or y = 0?No: 3≠0, -2≠02Check x signx > 0?Yes: 3 > 03Check y signy < 0?Yes: -2 < 0→ Quadrant IVQuadrant Classification4Point (3, -2)Located in Quadrant IVx > 0, y < 0Key Insight:Quadrant determination only requires checking coordinate signs - no complex calculations neededTutorialsPoint - Quadrant Finder | Nested Conditional Approach
Asked in
Microsoft 15 Google 12 Amazon 8
15.0K Views
Medium Frequency
~5 min Avg. Time
450 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen