Ctrl K

Restore the Lost Point

Medium
A log held a point on the plane, such as "(7, 0.25)". When the log was copied, the comma, the space and the decimal points got lost, leaving a string record like "(7025)". Return every way the original entry could have looked. Each number was written without redundant digits: no leading zeros ("05" and "00" are out, while "0" and "0.5" are fine), no trailing zero after the decimal point ("1.0" and "0.50" are out), and never an empty whole part (".5" is out). Format each option as "(x, y)" with exactly one space after the comma. The options may be returned in any order.
Example 1
record="(105)" → ['(1, 0.5)', '(10, 5)']

Split 1 | 05: 05 is not allowed but 0.5 is. Split 10 | 5: 1.0 is not allowed, 10 is. So (1, 0.5) and (10, 5).

Example 2
record="(2020)" → ['(20, 20)', '(2.02, 0)', '(20.2, 0)', '(202, 0)']

Anything ending in 0 must be a whole number without leading zeros, which leaves (20, 20), (2.02, 0), (20.2, 0) and (202, 0).

Example 3
record="(000)" → []

Neither 00 nor 0.0 is a valid number, so there is no option.

Constraints
  • 4 ≤ len(record) ≤ 12
  • record starts with ( and ends with )
  • Only digits appear between the brackets
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsNext Time From the Same Digits MediumPattern Woven Several Times HardKeypad Words MediumAll Balanced Bracket Strings MediumWord Traced on a Letter Grid Medium
loading Python…
Input
record="(105)"
Expected
['(1, 0.5)', '(10, 5)']

Run checks the first 3 tests in your browser. Submit checks all 81 tests on the server, hidden ones included.