Oracle/SMTS/IC3

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2025-08-18Added By Anonymous
Source: Link

Company: Oracle
Role: ic-3
Interview Stage: Coding Interview
Location: unknown
Year: unknown

Original Post Content:

Below problem was asked in a recent interview:

Biological Hazards

Problem Description

A biological researcher is studying bacteria interactions where certain bacteria are poisonous to others.
The samples are arranged consecutively in a row, numbered from 1 to n.

You are given two integer arrays allergic and poisonous of equal length m, where:

poisonous[i] is poisonous to allergic[i].

Your task is to determine the number of contiguous intervals [l, r] within the row such that all bacteria in that interval are capable of coexisting (i.e., no bacterium in the interval is poisonous to another bacterium in the same interval).

---

Example 1

Input:

n = 3
allergic = [2, 1, 3]
pois [3, 3, 1]

Output:

4

Explanation:

The bacteria are arranged as [1, 2, 3].

All possible intervals are: (1), (2), (3), (1,2), (2,3), (1,2,3).

Valid intervals are (1), (2), (3), (1,2).

Total valid intervals = 4

Comments