All problems
0193EasyTwo PointersString

Braided Bead Strands

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1768Merge Strings Alternately

This 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 jeweller braids two bead strands onto a single cord. Each strand arrives as text with one letter per bead, listed from the clasp outward: strandA and strandB.

The braid grows one bead at a time. First the clasp-most bead of strandA goes on, then the clasp-most bead of strandB, then the second bead of strandA, then the second bead of strandB, and the turns keep alternating like that. The moment one strand has nothing left to give, every bead still waiting on the other strand goes on in its own order and finishes the braid.

Return the finished braid as text.

Examples

Example 1

Input
strandA = "ruby", strandB = "jade"
Output
"rjuabdye"

Both strands hold four beads, so the turns alternate the whole way and neither strand has a leftover.

Example 2

Input
strandA = "opal", strandB = "tin"
Output
"otpianl"

Six beads alternate, then `strandB` is empty and the last bead of `strandA` closes the braid.

Example 3

Input
strandA = "gem", strandB = "amber"
Output
"gaemmber"

After six alternating beads `strandA` runs dry, so the two beads still on `strandB` follow in order.

Constraints

  • 1 <= strandA.length, strandB.length <= 100
  • strandA and strandB hold lowercase letters only

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def braid_strands(strandA: str, strandB: str) -> str:
Java
public String braidStrands(String strandA, String strandB)
September 7
Apply