FastPrepWormhole Spacecraft Overtakes
Problem · Array

Wormhole Spacecraft Overtakes

Learn this problem
MediumKickdrum logoKickdrumINTERNFULLTIMEOA

Problem statement

Distinct spacecraft enter a wormhole one at a time in entryOrder and emerge in exitOrder. Both arrays contain the same identifiers exactly once.

Two spacecraft crossed if the one that entered later emerged earlier. Return the number of distinct spacecraft that crossed at least one other spacecraft. Count each spacecraft at most once.

Function

countCrossingSpacecraft(entryOrder: String[], exitOrder: String[]) → int

Examples

Example 1

entryOrder = ["A","B","C","D"]exitOrder = ["A","C","B","D"]return = 2

B entered before C but emerged after it, so exactly those two spacecraft participated in a crossing.

Example 2

entryOrder = ["A","B","C"]exitOrder = ["C","B","A"]return = 3

Every spacecraft belongs to at least one inverted pair.

Constraints

  • 1 <= entryOrder.length = exitOrder.length <= 200000.
  • Each identifier contains 1 to 20 ASCII letters, digits, or underscores.
  • Every identifier occurs exactly once in each array.

More Kickdrum problems

drafts saved locally
public int countCrossingSpacecraft(String[] entryOrder, String[] exitOrder) {
    // Write your code here.
}
entryOrder["A","B","C","D"]
exitOrder["A","C","B","D"]
expected2
checking account