"Day 42 of #100DaysOfCode: String Arithmetic Challenge"

🚀 Day 42 of #100DaysOfCode — Leetcode + HackerRank Edition! Today’s challenge was a deep dive into string-based arithmetic — no shortcuts allowed! 🧩 multiply(num1: str, num2: str) -> str — Multiply two non-negative integers represented as strings, without using int() or BigInteger. 📌 Challenge: → No built-in conversion from string to integer → No BigInteger libraries → Just pure digit-by-digit simulation, like manual multiplication → Example: num1 = "123", num2 = "456" ✅ Output: "56088" 🔍 Approach: → Reversed both strings to simplify digit placement → Used ASCII math: ord(char) - ord('0') to extract digits → Stored intermediate products in an array of size len(num1) + len(num2) → Managed carry manually and built the final string from the result array 💡 What made it click: → Realized that each digit product lands at position i + j in the result array → Practiced dry runs to visualize how "123" * "456" becomes "56088" → Saw how carry propagation works across the array → Appreciated how reversing strings simplifies index math 📚 What I learned: ✅ How to simulate arithmetic without integer conversion ✅ How to use ASCII tricks to decode digits ✅ How to manage carry and build results step-by-step ✅ The power of dry runs to debug and understand logic Have you ever built a calculator or tackled string-based math problems? Let’s swap strategies and visual walkthroughs 💬 #Day42 #Leetcode #Python #StringManipulation #ASCIITricks #LearnInPublic #CodeNewbie #TechJourney #100DaysOfCode #DSA

  • graphical user interface, text, application

To view or add a comment, sign in

Explore content categories