Given an input string str, generate two output strings. One of which consists of those character which occurs only once in input string and second which consists of multi-time occurring characters. Output strings must be sorted.
Input : str = "geeksforgeeks" Output : String with characters occurring once: "for". String with characters occurring multiple times: "egks" Input : str = "geekspractice" Output : String with characters occurring once: "agikprst" String with characters occurring multiple times: "ce"
We have existing solution for this problem please refer Generate two output strings depending upon occurrence of character in input string link. We can solve this problem quickly in python using Counter(iterable) method. Approach is simple,
- Convert string into dictionary having characters as keys and their frequencies as value using counter() method.
- Now separate out list of characters having frequency 1 and having frequency more than 1.
- Sort characters in both lists to get output strings.
String with characters occurring once: for String with characters occurring multiple times: egks
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.
- Generate two output strings depending upon occurrence of character in input string.
- Index of character depending on frequency count in string
- Generate a string which differs by only a single character from all given strings
- Python | Replacing Nth occurrence of multiple characters in a String with the given character
- Program to count occurrence of a given character in a string
- Minimize the length of string by removing occurrence of only one character
- Count occurrence of a given character in a string using Stream API in Java
- Find the Nth occurrence of a character in the given String
- Remove the first and last occurrence of a given Character from a String
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Longest suffix such that occurrence of each character is less than N after deleting atmost K characters
- Rearrange given string to maximize the occurrence of string t
- Concatenate the strings in an order which maximises the occurrence of subsequence "ab"
- Generate all binary strings of length n with sub-string "01" appearing exactly twice
- Generate string with Hamming Distance as half of the hamming distance between strings A and B
- Generate a string from an array of alphanumeric strings based on given conditions
- Generate a String from given Strings P and Q based on the given conditions
- Using Counter() in Python to find minimum character removal to make two strings anagram
- Meta Strings (Check if two strings can become same after a swap in one string)
- Find a string such that every character is lexicographically greater than its immediate next character
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.