Biohazard Coexistence Intervals

Company: Uber_13aug

Difficulty: medium

Problem Statement

Biohazard Coexistence Intervals Problem Description A biological researcher is studying how bacteria interact. Some bacteria are poisonous to others. There are n different bacteria, numbered 1 to n , and one sample of each is placed in a row in that order: 1, 2, 3, ..., n . You are given m relationships as two arrays allergic and poisonous of length m : for every i , bacterium poisonous[i] is poisonous to bacterium allergic[i] . Two bacteria cannot coexist if either one is poisonous to the other, so the direction of a relationship does not matter. An interval [l, r] (with 1 <= l <= r <= n ) is the group of consecutive samples l, l + 1, ..., r . An interval is valid if it does not contain two bacteria that cannot coexist. Count the valid intervals. Complete the function bioHazard : int n : the number of bacteria (and of samples in the row). int allergic[m] : allergic[i] is allergic to poisonous[i] . int poisonous[m] : poisonous[i] is poisonous to allergic[i] . It returns a long