Given a string s, create a new string such that it contains the characters of the two halves of the string s combined alternately in reverse order.
Input : s = carbohydrates Output : hsoebtraarcdy Input : s = sunshine Output : sennuish
Example 1: Two halves of the string carbohydrate are carboh and ydrates. As they needed to be added in reverse alternately, start with h from first half then s from second half followed by o from first half, e from second half and so on. The string p comes out to be hsoebtraarcdy. If one of the string is completely finished then simply add the remaining characters of the other string in reverse order.
Example 2: The two halves of the string are suns and hine. String sennuish is the desired string p.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Check if both halves of the string have same set of characters
- Check if both halves of the string have same set of characters in Python
- Reverse alternate k characters in a string
- Reverse a string without affecting special characters
- Check if both halves of the string have at least one different character
- Transform string str1 into str2 by taking characters from string str3
- Lexicographically smallest string formed by appending a character from the first K characters of a given string
- Lexicographically smallest string formed by appending a character from first K characters of a string | Set 2
- Minimal moves to form a string by adding characters or appending string itself
- Minimum deletions from string to reduce it to string with at most 2 unique characters
- Find the smallest window in a string containing all characters of another string
- Count of times second string can be formed from the characters of first string
- Find Kth largest string from the permutations of the string with two characters
- String matching where one string contains wildcard characters
- Check whether second string can be formed from characters of first string
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.