⌘K
Flycodx

Sugar Mill Batch Production Sequencing

Sugar Mill Batch Production Sequencing

HardArrays100% accepted

Ravi manages a Maharashtra sugar mill processing different raw material batches. Equipment constraints forbid certain batch sequences (e.g., can't process type B directly after type A). Given N batches with forbidden pairs, find the longest valid production sequence satisfying all constraints. Rule: forbidden pairs are ORDERED: [a,b] forbids type b immediately after type a. Return the longest contiguous run with no forbidden adjacent pair. Your solve(...) function receives the inputs as ready-made arguments — no input reading or parsing needed; just return the answer.

Approach

Given array of batch types and list of forbidden consecutive pairs, find the longest valid sequence of length N.

Input

batches=[1,2,3,2,1] forbidden=[[1,2],[2,3]]

Output

3
solution.py
Loading editor...
Test 1
Test 2
Test 3

Press Run to test your custom input, or Submit to judge against all test cases.

Sign in to continue

Create a free account to run code, submit solutions and track progress.

  • Free forever — no credit card
  • 10+ languages with live execution
  • Points, streaks & leaderboards
Auto Save OnLn 1, Col 1Spaces: 4UTF-8LFPython 3