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!
Create an Account
Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.
Create accountHow 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 Feb 2026
Contest runs February 1 - 28. Complete challenges to climb the leaderboard!
Points are calculated for challenges completed during the contest period.