2dbi
Home/ServiceNow/Longest Increasing Subsequence
SServiceNow·DSAIC2Online Assessment

Longest Increasing Subsequence

Problem

Find the length of the longest strictly increasing subsequence in an array.

Example

[10,9,2,5,3,7,101,18] -> 4 ([2,3,7,101])

Constraints

  • 1 ≤ n ≤ 2500

Approach

O(n^2) DP, or O(n log n) with patience sorting + binary search. Reported ServiceNow OA question.

added 6 days ago
LeadersAccount