P15 · 2 seconds · 256 MB

Longest Increasing Subsequence

Given an integer array `nums`, return the length of the longest strictly increasing subsequence. A subsequence keeps relative order and need not be contiguous. Equal values are not increasing. Return the length only — you do not need to reconstruct a sequence.

function lengthOfLIS(nums) → number

CONSTRAINTS

  • 1 ≤ nums.length ≤ 2000
  • -10⁶ ≤ nums[i] ≤ 10⁶
Input: nums = [10, 9, 2, 5, 3, 7, 101, 18]
Output: 4
[2, 5, 7, 101] or [2, 3, 7, 101] or [2, 3, 7, 18].
Input: nums = [0, 1, 0, 3, 2, 3]
Output: 4
[0, 1, 2, 3].
Input: nums = [7, 7, 7, 7]
Output: 1
1
2
3
4
5
6
7
8

Arena judges JavaScript in a Web Worker (1s wall-clock, then TLE). Samples are public; submit runs hidden tests too. C++/Python is a later swarm package.