Given two binary strings a and b, return their sum as a binary string. Binary strings contain only the characters '0' and '1'. Do not convert the binary strings to integers - simulate the binary addition directly by processing each string from right to left, tracking the carry at each step.

Examples:

Input: a = '11', b = '1' Output: '100' Explanation: 11 (3) + 1 (1) = 100 (4) in binary Input: a = '1010', b = '1011' Output: '10101' Explanation: 1010 (10) + 1011 (11) = 10101 (21) in binary Input: a = '0', b = '0' Output: '0' Explanation: 0 + 0 = 0 Input: a = '1', b = '0' Output: '1' Explanation: 1 + 0 = 1 Input: a = '111', b = '111' Output: '1110' Explanation: 111 (7) + 111 (7) = 1110 (14) in binary
Apex Code Editor

Welcome to Lightning Challenge!

How It Works

  • • Write your solution in the code editor
  • • Connect your Salesforce org to test
  • • Submit to check if your solution passes
  • • Use hints if you get stuck

Contest Alert

🏆 #CodeEveryDay August 2026

Contest runs August 1 - 31. Complete challenges to climb the leaderboard!

Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In