Ambiguous Coordinates - Problem
Imagine you're a forensic data analyst tasked with reconstructing corrupted GPS coordinates! You have a string that represents coordinates where all formatting has been stripped away - no commas, decimal points, or spaces remain.
Your mission: determine all possible valid coordinate pairs that could have produced this string.
The Challenge: Given a string like "(205)", figure out if it could represent coordinates like "(2, 0.5)", "(20, 5)", or "(2.0, 5)".
Important Rules:
- ๐ซ No leading zeros in integers (avoid "001", "00.5")
- ๐ซ No trailing zeros in decimals (avoid "1.0", "2.50")
- ๐ซ No decimals starting with a point (avoid ".5")
- โ Each coordinate must have exactly one space after the comma
Goal: Return a list of all possible valid coordinate representations that could have produced the input string.
Input & Output
example_1.py โ Basic Split
$
Input:
s = "(123)"
โบ
Output:
["(1, 23)", "(12, 3)", "(1.2, 3)", "(1, 2.3)"]
๐ก Note:
We can split '123' as '1|23' or '12|3'. For '1|23': (1, 23), (1, 2.3). For '12|3': (12, 3), (1.2, 3). All combinations are valid.
example_2.py โ Leading Zero Edge Case
$
Input:
s = "(0123)"
โบ
Output:
["(0, 123)", "(0, 12.3)", "(0, 1.23)", "(0.1, 23)", "(0.1, 2.3)", "(0.12, 3)"]
๐ก Note:
The first digit '0' must be standalone (no leading zeros for multi-digit). So splits like '01|23' are invalid, but '0|123' works. Decimal '0.1|23' is valid.
example_3.py โ Trailing Zero Edge Case
$
Input:
s = "(100)"
โบ
Output:
["(10, 0)", "(1, 00)"]
๐ก Note:
Wait, this is wrong! Let me recalculate: '10|0' gives (10, 0) which is valid. '1|00' would be (1, 00) but '00' has leading zeros so it's invalid. Correct answer: ["(10, 0)"]
Constraints
- 4 โค s.length โค 12
- s[0] == '(' and s[s.length - 1] == ')'
- The rest of s are digits
- No extraneous leading zeros in original coordinates
- No trailing zeros in decimal representations
Visualization
Tap to expand
Understanding the Visualization
1
Split Candidates
Try splitting the inner digits at each position
2
Number Generation
For each part, generate all valid integer and decimal forms
3
Validation
Check each number against no-leading-zeros and no-trailing-zeros rules
4
Combination
Combine valid left and right parts into coordinate format
Key Takeaway
๐ฏ Key Insight: Systematically enumerate all splits, then generate valid decimal representations while enforcing the no-leading-zeros and no-trailing-zeros constraints.
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code