Binary Addition Exercise: Understanding Carry and Result

🚀𝐃𝐚𝐲 88/100 – 𝐀𝐝𝐝 𝐁𝐢𝐧𝐚𝐫𝐲 Today’s problem was Add Binary — a great exercise to understand how addition works at the binary level. 🔍 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠: Just like decimal addition, binary addition also uses a carry, but with base 2. 💡 𝐂𝐨𝐫𝐞 𝐈𝐝𝐞𝐚: Traverse both strings from right to left Add digits along with carry Append result and update carry  𝐖𝐡𝐲 𝐢𝐭 𝐰𝐨𝐫𝐤𝐬? Binary addition rules: 0 + 0 = 0 1 + 0 = 1 1 + 1 = 0 (carry 1) ⚡ 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Use two pointers (end of both strings) Add digits + carry Append (sum % 2) Update carry (sum / 2) Reverse the result ⏱️ 𝐓𝐢𝐦𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝐦𝐚𝐱(𝐧, 𝐦)) 📦 𝐒𝐩𝐚𝐜𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝐧) #Day88 #100DaysOfCode #Java #DSA #LeetCode #Strings #CodingJourney

  • graphical user interface, text

To view or add a comment, sign in

Explore content categories