An N pair array is given to you. In every pair, the first number is always smaller than the second number. A pair (a,b) can follow another pair (c,d) if a is greater than d
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
To print the longest chain from N pairs is a problem of combination and permutation. If we go with the recursive approach then it will take a long time.
let f(i) = maximum chain length among ith pairs.
To solve this problem, we will follow these steps,
f(current element)=max(f(current element), f(element having the second element is smaller than it)).
To print the chains, we follow this approach,
C++ Implementation:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer