BackmediumStack Amazon

Galactic Coordinate Parser Solution

Problem Statement

Given a string of galactic coordinates in the format of (latitude, longitude), determine if the coordinates are properly nested, i.e., every open parenthesis has a corresponding close parenthesis and the pairs of coordinates are properly nested.

Example 1
Input
(1, 2) (3, 4)
Output
True

Explanation: Step-by-step: with input (1, 2) (3, 4), we first check if the first parenthesis is properly nested, which it is. Then, we check if the second parenthesis is properly nested, which it is. Since both parentheses are properly nested, the output is True.

Example 2
Input
(1, 2) (3, 4))
Output
False

Explanation: Step-by-step: with input (1, 2) (3, 4)), we first check if the first parenthesis is properly nested, which it is. Then, we check if the second parenthesis is properly nested, which it is not because there is no corresponding opening parenthesis. Since the second parenthesis is not properly nested, the output is False.

Constraints

  • The input string will contain at most 1000 sets of coordinates.
  • Each set of coordinates will be in the format of (latitude, longitude) where latitude and longitude are decimal numbers between -90 and 90 and -180 and 180 respectively.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free