I recently came across an interview question asked by Google and I am not able to find an optimized algorithm to solve this question:
Given 2 numbers a and b. Divide a and b and return result in form of a string.
Example 1
Input: a=100 , b=3
Output: 33.(3)
Note: (100/3)=33.33333....Here 3 is in brackets because it gets repeated continuously.
Example 2
Input: a=5 , b=10
Output: 0.5
Example 3
Input: a=51 , b=7
Output: 7.(285714)
Note: 51/7 = 7.285714285714285714285714285714......... Here 285714 is in brackets because it is repeating.
It would be great if anyone can think of a time-optimized algorithm for this question. Thank You in advance.