Trains the technique from
LeetCode 67Add BinaryThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A test rig has two long rows of toggle switches. A row is recorded as a string of the characters '0' and '1', one character per switch, the most significant switch written first, and the row is read as a count in base two. A recorded row never opens with '0' unless the whole row is the single character '0'.
Given the recorded rows top and bottom, return the row that would show their combined count. Use the same format: base two, most significant switch first, and no opening '0' unless the combined count is zero, in which case the answer is the single character '0'.
A row can hold far more switches than the rig's registers can count, so settle the columns one at a time from the least significant switch, carrying into the next column, rather than reading a whole row into a single number.
Example 1
The rows stand for eleven and six, and the seventeen they combine to is written 10001 in base two.
Example 2
The rows stand for nineteen and thirteen, and the thirty-two they combine to is written 100000 in base two.
Example 3
The top row is zero, so the combined count matches the bottom row and is written the same way.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def combine_toggle_rows(top: str, bottom: str) -> str:public String combineToggleRows(String top, String bottom)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.