Merge two strings by adding letters in alternating order, starting with word1. If one string is longer, append the remaining letters to the end.

Input: word1="abc", word2="pqr" → Output: "apbqcr"Input: word1="ab", word2="pqrs" → Output: "apbqrs"

Use two pointers advancing through both strings simultaneously. Append from word1 then word2 in turns.

class Solution { public String mergeAlternately(String word1, String word2) { StringBuilder sb = new StringBuilder(); int i = 0, j = 0; while (i < word1.length() || j < word2.length()) { if (i < word1.length()) sb.append(word1.charAt(i++)); if (j < word2.length()) sb.append(word2.charAt(j++)); } return sb.toString(); } }