Recursive Character Frequency
Updated
Problem statement
Count how many times each character appears in text. Capital letters A to Z count as their small letters, so A and a share one count. Every other character is counted as it is.
Return one entry for each different character, sorted by ASCII code from smallest to largest. Write each entry as character=count, except the space, which is written as space=count.
The interviewer asked for a recursive solution: walk through the string with recursion instead of a for or while loop.
Function
recursiveCharacterFrequency(text: String) → String[]Examples
Example 1
text = "This is PANW Interview"return = ["space=3","a=1","e=2","h=1","i=4","n=2","p=1","r=1","s=2","t=2","v=1","w=2"]After folding capital letters, the text is "this is panw interview". It has 3 spaces, and for example i appears 4 times (this, is, interview twice). The space has the smallest code (32), so space=3 comes first, and the letters follow in alphabetical order.
Example 2
text = "Aa!!"return = ["!=2","a=2"]A folds to a, so a appears 2 times. The two ! stay as they are. ! has code 33 and a has code 97, so !=2 comes first.
Constraints
0 ≤ text.length ≤ 500- Every character of
textis printable ASCII (codes 32 to 126).
More Palo Alto Networks Onsite Interview questions
Similar questions at other companies
- Nested Set Structural EquivalencePinterest · PHONE SCREEN · ONSITE INTERVIEW
- Count Adjacent Symbol Pairs for BPEAmazon · ONSITE INTERVIEW
- Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEW
- Filter Anagrams of a TargetMicrosoft · ONSITE INTERVIEW
- Deduplicate Logs: Keep FirstGoogle · ONSITE INTERVIEW
- Check AnagramsDeloitte · ONSITE INTERVIEW
- Check AnagramsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEW
- Check Anagram Pairs Index by IndexExpedia · ONSITE INTERVIEW
- Valid AnagramMotive · ONSITE INTERVIEW
- Anagram Words in a SentenceNutanix · ONSITE INTERVIEW