Create a method that counts the occurrences of each character in a string and returns a map where keys are characters and values are their frequency counts.
Examples:
Input: input = "hello"
Output: {'h' => 1, 'e' => 1, 'l' => 2, 'o' => 1}
Explanation: 'h', 'e', and 'o' appear once each, while 'l' appears twice
Input: input = "salesforce"
Output: {'s' => 2, 'a' => 1, 'l' => 1, 'e' => 2, 'f' => 1, 'o' => 1, 'r' => 1, 'c' => 1}
Explanation: 's' and 'e' appear twice each, while all other characters appear once
Apex Code Editor
Welcome to Lightning Challenge!
How It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay July 2026
Contest runs July 1 - 31. Complete challenges to climb the leaderboard!
Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.