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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Java program to merge two files alternatively into third file
- Merge two strings in chunks of given size
- Pairs of complete strings in two sets of strings
- Meta Strings (Check if two strings can become same after a swap in one string)
- Number of common base strings for two strings
- Count of strings that become equal to one of the two strings after one removal
- Count of same length Strings that exists lexicographically in between two given Strings
- Check whether two strings can be made equal by reversing substring of equal length from both strings
- Merge two sorted arrays in Python using heapq
- Number of ways to merge two arrays such retaining order
- Compare two strings lexicographically in Java
- Search in an array of strings where non-empty strings are sorted
- Count of distinct Strings possible by swapping prefixes of pairs of Strings from the Array
- Distinct strings such that they contains given strings as sub-sequences
- Print all Strings from array A having all strings from array B as subsequence
- Search strings with the help of given pattern in an Array of strings
- Print all strings of maximum length from an array of strings
- Concurrent Merge Sort in Shared Memory
- merge() in C++ STL
- Merge 3 Sorted Arrays
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.