Skip to content

Latest commit

 

History

History
17 lines (12 loc) · 797 Bytes

File metadata and controls

17 lines (12 loc) · 797 Bytes

Sum Binary String Values

Problem Definition:

Implement a function that takes two strings of binary values and adds them.

Example:

String value1 = "110"; // 6
String value2 = "101"; // 5
String sum = addBinary(value1, value2); // result is 1011 = 11

Notes:

  • I've encountered the problem during a Facebook Phone Interview
  • Learned an interesting tidbit about Java's StringBuilder. I had assumed there was a handy prepend function, but there is only insert which seems inefficient. It's better to append values and later reverse (See: Stack Overflow Question 1, Question 2).