Given 2 strings, merge them in an alternate way, i.e. the final string’s first character is the first character of the first string, the second character of the final string is the first character of the second string and so on. And if once you reach end of one string while if another string is still remaining then append the remaining of that string to final string
Input : string 1 :"geeks" string 2 :"forgeeks" Output: "gfeoerkgseeks" Explanation : The answer contains characters from alternate strings, and once the first string ends the remaining of the second string is added to the final string Input :string 1 :"hello" string 2 :"geeks" Output : hgeelelkos
The idea is simple, we create a result string. We one by one append characters of both given strings in alternate style.
- Java program to merge two files alternatively into third file
- Merge two strings in chunks of given size
- Compare two strings lexicographically in Java
- Meta Strings (Check if two strings can become same after a swap in one string)
- Search in an array of strings where non-empty strings are sorted
- Pairs of complete strings in two sets of strings
- Count of strings that become equal to one of the two strings after one removal
- Number of common base strings for two strings
- Distinct strings such that they contains given strings as sub-sequences
- merge() in C++ STL
- Sorted merge in one array
- Merge 3 Sorted Arrays
- In-Place Merge Sort
- Concurrent Merge Sort in Shared Memory
- Merge two sorted arrays in Python using heapq
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.