1051. Return All Duplicate Characters in a String
You are given a string s consisting of lowercase English letters ('a' to 'z').
Your task is to return all characters that occur more than once in the string, along with their occurrence count.
Return the result as a space-separated string where each entry is formatted as character + count.
The output should be sorted in lexicographical order of characters.
Example 1:
Input: s = "aabbcc"
Output: "a2 b2 c2"
Explanation: Each of 'a', 'b', and 'c' occurs twice.
Example 2:
Input: s = "abcde"
Output: ""
Explanation: No duplicates, so return empty string.
Now Your Turn!
Pick the correct output for the given inputInput: s = "aabccd"
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= s.length <= 105
- s contains only lowercase English letters