Given an encrypted string str, the task is to decrypt the given string when the encryption rules are as follows:
- Start with the first character of the original string.
- In every odd step, append the next character to it.
- In every even step, prepend the next character to the encrypted string so far.
For example, if str = “geeks” then the encrypted string will be,
g -> ge -> ege -> egek -> segek
Input: str = “segosegekfrek”
Input: str = “vrstie”
Approach: The steps that are given to encrypt the string can be followed in reverse order to obtain the original string. There will be two conditions to obtain the original string:
- If the string is of odd length, in odd step add the characters from the back in the resultant string, else add from the front.
- If the string is of even length, in odd step add characters from the front and add characters from back in even step.
The reverse of the resultant string thus obtained is the original string which was encrypted.
Below is the implementation of the above approach:
- Check a given sentence for a given set of simple grammer rules
- Lexicographically smallest string formed by appending a character from the first K characters of a given string
- Create a new string by alternately combining the characters of two halves of the string in reverse
- String slicing in Python to check if a string can become empty by recursive deletion
- Minimal moves to form a string by adding characters or appending string itself
- Find the count of palindromic sub-string of a string in its sorted form
- Find length of longest subsequence of one string which is substring of another string
- Find the character in first string that is present at minimum index in second string
- Minimum deletions from string to reduce it to string with at most 2 unique characters
- Decode an Encoded Base 64 String to ASCII String
- Covert string X to an anagram of string Y with minimum replacements
- Minimum changes required to make first string substring of second string
- Check if a string can become empty by recursively deleting a given sub-string
- Convert the string into palindrome string by changing only one character.
- Remove characters from a numeric string such that string becomes divisible by 8