FastPrepCharacter Intersection and Frequency Ordering

Character Intersection and Frequency Ordering

Bloomberg LP logoBloomberg LP● MediumNEW GRADONSITE INTERVIEW
Learn

Problem statement

Return a two-element array:

  1. A string containing each distinct character present in both inputs, in first-appearance order from first.
  2. A string containing every distinct character from both inputs ordered by descending combined frequency. Break ties by first appearance while scanning first then second.

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.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public String[] intersectionAndFrequencyOrder(String first, String second) {
  // Write your code here.
}
first"ABCEGDB"
second"ABACE"
expected["ABCE", "ABCEGD"]
Checking account…