Given a string str, the task is to encrypt the string with the given encryption algorithm.
The 1st character of the string will be repeated once in the encrypted string, the 2nd character will be repeated twice, …, nth character will be repeated n times.
For example, str = “abcd” will be encrypted as “abbcccdddd”.
Input: str = “geeks”
Input: str = “abcd”
Approach: Initialize cnt = 1 and start traversing the string character by character. Repeat the current character cnt number of times then update cnt = cnt + 1 and get to the next character. Repeat these steps for every character of the string.
Below is the implementation of the above approach:
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.
- Decrypt a string encrypted by repeating i-th character i times
- Replace every character of string by character whose ASCII value is K times more than it
- Queries to find the first non-repeating character in the sub-string of a string
- Queries to find the last non-repeating character in the sub-string of a given string
- Find the last non repeating character in string
- First non-repeating character using one traversal of string | Set 2
- Given a string, find its first non-repeating character
- Maximum consecutive repeating character in string
- Find first non-repeating character in a given string using Linked List
- Print the string after the specified character has occurred given no. of times
- Check if max occurring character of one string appears same no. of times in other
- Program to Encrypt a String using ! and @
- Encrypt the given string with the following operations
- Encrypt a string into the Rovarspraket (The Robber Language)
- K'th Non-repeating Character
- Encrypt string with product of number of vowels and consonants in substring of size k
- Find the first non-repeating character from a stream of characters
- K’th Non-repeating Character in Python using List Comprehension and OrderedDict
- Queue based approach for first non-repeating character in a stream
- Count of substrings which contains a given character K times
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.