Given two strings ‘a’ and ‘b’ and a number k, our aim is to merge the strings into a string s such that it contains groups of k characters from the strings alternately in the final string.
Input: a = "durability", b = "essence k = 3 Output: duressabienclitey Input: a = "determination" b = "stance" k = 3 Output: detstaermnceination
In the second example we chose groups of three characters from determination and stance alternately to make the string. But when the string stance was completely used then we added the remaining string of determination as it is.
The approach of this problem is to alternately add groups of characters of both the strings until one of the string is finished. Then we simply have to add the remaining portion of the leftover string to the answer as it is.
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.
- Alternatively Merge two Strings in Java
- Count of N size strings consisting of at least one vowel and one consonant
- Generate a string of size N whose each substring of size M has exactly K distinct characters
- 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
- Count of same length Strings that exists lexicographically in between two given Strings
- Count of strings that become equal to one of the two strings after one removal
- Pairs of complete strings in two sets of strings
- Number of common base strings for two strings
- Distinct strings such that they contains given strings as sub-sequences
- Check whether two strings can be made equal by reversing substring of equal length from both strings
- Concurrent Merge Sort in Shared Memory
- Print all Strings from array A having all strings from array B as subsequence
- Lexicographically smallest and largest substring of size k
- Generate random String of given size in Java
- Count of K-size substrings having palindromic permutations
- Binary String of given length that without a palindrome of size 3
- Find the size of largest subset of anagram words
- Minimum flips required in a binary string such that all K-size substring contains 1
- Encrypt string with product of number of vowels and consonants in substring of size k
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.
Improved By : manishshaw1