Longest increasing subsequence

Python data engineering interview problem. Difficulty: advanced. Pattern: Dynamic Programming. About 20 minutes. Part of the Pro drill bank.

Length of the longest strictly increasing subsequence of a list. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.

A metric series may improve over time with noisy values between improvements. A subsequence can skip noise but must keep original order. Return the length of the longest strictly increasing subsequence. Equal values do not increase the length. Write lis_length(nums: list[int]) -> int. In [2,2,3,3], choose one 2 and one 3, so the strict length is 2. The starter file already contains the function name, harness and print lines. Keep them and fill only the function body.

Requirements

  • Preserve original order.
  • Allow skipped values.
  • Require every next value to be strictly larger.

Constraints

  • The input may be empty and values can repeat.
  • Return an integer length.

Examples

Input: lis_length([2, 2, 3, 3]) Output: 2 The repeated values do not extend a strictly increasing subsequence: 2, 3 is the longest, so the length is 2.

Topics: lakebench, python, subsequence, patience sorting.

More Python interview questions · All interview problems · Learn data engineering

advanced

Longest increasing subsequence

Interview-style drill: Length of the longest strictly increasing subsequence of a list.

Implement `lis_length(nums: list[int]) -> int`. A subsequence keeps the original order but may skip elements. Return the length of the longest **strictly** increasing subsequence of `nums`. Equal values do not extend a subsequence. An empty list gives `0`.