Minimum Disorder Events

Company: Deshaw full time_15march

Difficulty: medium

Problem Statement

Minimum Disorder Events A system receives two separate log streams, logStreamA and logStreamB . The two streams must be merged into a single output sequence that preserves the relative order of the entries inside each stream. For example, if logStreamA = "abc" and logStreamB = "def" , then "abcdef" and "defabc" are valid merges, and so is "adbecf" . Sequences such as "acdbef" or "abcdfe" are not valid merges, because they break the original ordering of the entries of at least one stream. Every entry is a single lowercase letter. After merging, the system scores the output by counting its disorder events . A disorder event is a pair of positions (i, j) with i < j such that mergedLogs[i] > mergedLogs[j] — an entry that arrives earlier is strictly greater than an entry that arrives later. Two equal entries never form a disorder event. Report the minimum number of disorder events over all valid merges of logStreamA and logStreamB . Input Format Line 1: the string logStreamA . Line 2: