Ctrl K

Do Repeating Decimals Match

Hard
You get two strings first and second, each the notation of a non-negative rational number. Return True if they denote the same number and False otherwise. A notation takes one of three forms: - an integer part only: 7, 0, 250; - an integer part, a dot and an optional finite fractional part: 0.25, 3., 12.0408; - the same followed by a period in parentheses that repeats forever: 0.(6), 1.2(45), 5.(9). For instance, 0.1(6), 0.16(6) and 0.1(66) all mean 0.1666… = 1/6.
Example 1
first="0.(36)", second="0.3(63)" → True

Both stand for 0.363636…

Example 2
first="2.4(9)", second="2.5" → True

2.4999… with nines forever is exactly 2.5.

Example 3
first="0.(3)", second="0.33" → False

0.333… is 1/3, while 0.33 is a little less.

Constraints
  • Every part consists of digits
  • The integer part has 1 to 4 digits and no leading zeros (except the number 0 itself)
  • The fractional part before the parentheses has 0 to 4 digits
  • The period has 1 to 4 digits
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPlus-Minus Calculator With Brackets HardAmount in Words HardSigns Between the Digits HardNearest Palindrome Number HardSimplify a Letter Polynomial Hard
loading Python…
Input
first="0.(36)", second="0.3(63)"
Expected
True

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