Daily challenge for 2026-08-21
598. Alternate Word Endings
Given two strings s1 and s2, and an integer k, extract the last k characters of each string. If a string has fewer than k characters, extract the entire string. Interleave the two extracted substrings character by character, starting with the first character of the substring from s1, followed by the first of s2, the second of s1, and so on. If one substring is longer than the other, append the remaining characters of the longer substring to the end of the result.
Example:
Input: s1 = "apple", s2 = "banana", k = 3
Output: "palnea"
Explanation: The last 3 characters of "apple" are "ple", and the last 3 characters of "banana" are "ana". Interleaving them yields 'p' + 'a' + 'l' + 'n' + 'e' + 'a' = "palnea".
Run this challenge interactively in Python or JavaScript when the app loads.