Character Intersection and Frequency Ordering
Problem statement
Return a two-element array:
- A string containing each distinct character present in both inputs, in first-appearance order from
first. - A string containing every distinct character from both inputs ordered by descending combined frequency. Break ties by first appearance while scanning
firstthensecond.
Function
intersectionAndFrequencyOrder(first: String, second: String) → String[]Examples
Example 1
first = "ABCEGDB"second = "ABACE"return = ["ABCE","ABCEGD"]A and B occur three times, C and E twice, and G and D once; ties follow first appearance.
Constraints
- Inputs contain ASCII characters and total length is at most
2 * 10^5.