Problem
Ask
Submissions

Problem: Equal Rational Numbers

Medium
30 min
Understand how to determine the equality of two rational numbers given as strings that may include repeating decimal parts. Learn to interpret integer, non-repeating, and repeating sections, handle multiple valid representations, and implement solutions to verify numerical equivalence.

Statement

Given two strings s and t, each representing a non negative rational number, return true if and only if they represent the same number. The strings may use parentheses to denote the repeating part of the rational number.

A rational number can be represented using up to three parts: <IntegerPart>, <NonRepeatingPart>, and <RepeatingPart>. The number will be expressed in one of the following three formats:

  • <IntegerPart>

    • For example, 1212, 00, and 123123.

  • <IntegerPart><.><NonRepeatingPart>

    • For example, 0.50.5, 1.1., 2.122.12, and 123.0001123.0001.

  • <IntegerPart><.><NonRepeatingPart><(><RepeatingPart><)>

    • For example, 0.1(6)0.1(6), 1.(9)1.(9), 123.00(1212)123.00(1212).

The repeating portion of a decimal expansion is conventionally denoted within a pair of round brackets. For example:

1/6=0.16666666...=0.1(6)=0.1666(6)=0.166(66)1/6 = 0.16666666... = 0.1(6) = 0.1666(6) = 0.166(66)

Note: The same rational number may have multiple valid representations using different placements of the repeating block.

Constraints:

  • Each part consists only of digits.

  • The <IntegerPart> does not have leading zeros (except for the zero itself).

  • 11 \leq <IntegerPart>.length 4\leq 4

  • 00 \leq <NonRepeatingPart>.length 4\leq 4

  • 11 \leq <RepeatingPart>.length 4\leq 4

Problem
Ask
Submissions

Problem: Equal Rational Numbers

Medium
30 min
Understand how to determine the equality of two rational numbers given as strings that may include repeating decimal parts. Learn to interpret integer, non-repeating, and repeating sections, handle multiple valid representations, and implement solutions to verify numerical equivalence.

Statement

Given two strings s and t, each representing a non negative rational number, return true if and only if they represent the same number. The strings may use parentheses to denote the repeating part of the rational number.

A rational number can be represented using up to three parts: <IntegerPart>, <NonRepeatingPart>, and <RepeatingPart>. The number will be expressed in one of the following three formats:

  • <IntegerPart>

    • For example, 1212, 00, and 123123.

  • <IntegerPart><.><NonRepeatingPart>

    • For example, 0.50.5, 1.1., 2.122.12, and 123.0001123.0001.

  • <IntegerPart><.><NonRepeatingPart><(><RepeatingPart><)>

    • For example, 0.1(6)0.1(6), 1.(9)1.(9), 123.00(1212)123.00(1212).

The repeating portion of a decimal expansion is conventionally denoted within a pair of round brackets. For example:

1/6=0.16666666...=0.1(6)=0.1666(6)=0.166(66)1/6 = 0.16666666... = 0.1(6) = 0.1666(6) = 0.166(66)

Note: The same rational number may have multiple valid representations using different placements of the repeating block.

Constraints:

  • Each part consists only of digits.

  • The <IntegerPart> does not have leading zeros (except for the zero itself).

  • 11 \leq <IntegerPart>.length 4\leq 4

  • 00 \leq <NonRepeatingPart>.length 4\leq 4

  • 11 \leq <RepeatingPart>.length 4\leq 4