FastPrepRecursive Character Frequency

Recursive Character Frequency

Palo Alto Networks logoPalo Alto Networks● EasyFULLTIMEONSITE INTERVIEW
Learn

Problem statement

Count character frequencies in text by traversing the string recursively, without an explicit loop. Fold ASCII letters A through Z to lowercase before counting; leave other printable ASCII characters unchanged.

Return one entry per distinct folded character in ascending ASCII order. Encode a space as space=count and every other character as character=count.

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"]

Uppercase letters fold to lowercase, three spaces are counted, and the entries follow ASCII order.

Example 2

text = "Aa!!"return = ["!=2","a=2"]

A and a share one folded count, while the exclamation mark remains unchanged.

Constraints

  • 0 <= text.length <= 500.
  • Every character has an ASCII code from 32 through 126.
  • The submitted traversal must be recursive and must not use explicit looping statements.

More Palo Alto Networks problems

See Palo Alto Networks hiring insights
public String[] recursiveCharacterFrequency(String text) {
    // Write your code here.
}
text"This is PANW Interview"
expected["space=3", "a=1", "e=2", "h=1", "i=4", "n=2", "p=1", "r=1", "s=2", "t=2", "v=1", "w=2"]
Checking account…