Most and Least Frequent Characters
Updated
Problem statement
Given a string s, find the character that occurs most often in it and the character that occurs least often. Only characters that appear in s count, and upper and lower case letters are different characters.
If several characters share the highest count, pick the one whose first appearance in s comes earliest. Break ties for the lowest count the same way.
Return [most, least], each as a one-character string.
Function
mostAndLeast(s: String) → String[]Examples
Example 1
s = "kettle7tea"return = ["e","k"]Counts: t 3, e 3, k 1, l 1, 7 1, a 1. t and e tie for the most; e appears first (index 1), so it wins. Four characters tie for the least; k appears first (index 0).
Example 2
s = "Zoozoo"return = ["o","Z"]Upper and lower case are different characters: o appears 4 times, Z and z once each. Z appears before z, so it is the least frequent.
Example 3
s = "88"return = ["8","8"]Only one distinct character, so it is both the most and the least frequent.
Constraints
1 <= s.length <= 5 * 10^4sconsists of English letters (upper and lower case) and digits.
More Adobe Phone Screen questions
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
- All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
- Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
- Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
- Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
- Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- Detect a Straight FlushTemu · PHONE SCREENTemu interview questions
- First Letter to Appear TwiceCisco · PHONE SCREENCisco interview questions
- Halfway Course in a Single TrackCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Portfolio Valuation, Part 1Stripe · PHONE SCREENStripe interview questions
- Single-Condition Product FilterCrowdstrike · PHONE SCREENCrowdstrike interview questions
- Summarize Server Healthcheck LogsNVIDIA · PHONE SCREENNVIDIA interview questions
- Known Words Matching Phone DigitsLinkedIn · PHONE SCREENLinkedIn interview questions
- First Non-Repeated CharacterDell Technologies · PHONE SCREENDell Technologies interview questions
- Convert an Entry List to a MapEPAM · PHONE SCREENEPAM interview questions
- First Non-Repeating CharacterGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions