Hey everyone 👋
Day 9 of my LeetCode streak! Today wasn’t the smoothest — I was working from a café instead of my desk ☕, so no video walkthrough this time. But the streak must go on 💪.
📝 Problem Summary
We’re dividing two integers and returning the result as a string.
If the decimal terminates → just return it.
If the decimal repeats → wrap the repeating digits in parentheses 🔄.
Examples:
1/2 → "0.5"
2/1 → "2"
4/333 → "0.(012)"
💡 Key Insight
When doing long division, a repeating remainder means the digits will start repeating too.
So, track remainders in a map and insert parentheses once a cycle is detected.
I’ve covered the full intuition, step-by-step approach, edge cases, and JavaScript code on my blog 👇
🔗 https://nitinahirwal.in/posts/166-FractiontoRecurringDecimal
Day 9 done ✅ — excited for Day 10 tomorrow 🚀
Top comments (0)