FastPrepLongest Increasing Subsequence
Problems/Longest Increasing Subsequence

Longest Increasing Subsequence

ByteDance logoByteDance● MediumINTERNPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: In the first of two TikTok phone rounds for a 2026 summer internship on a TikTok GMPT team, after questions about the resume, the candidate coded the classic longest increasing subsequence task with its fastest known method right away. The interviewer then asked whether a quadratic method also works, and the candidate rewrote the solution as a dynamic program.

The report names the public problem only. Practice choices here: the standard form (the length of the longest strictly increasing subsequence), 1 to 2500 values from -10^4 to 10^4, and our own examples; the editorial covers both the quadratic and the faster method.

The judged task matches the report at about 90%.

Given an integer array nums, return the length of its longest strictly increasing subsequence.

A subsequence keeps some of the elements in their original order, possibly skipping others; the kept elements do not have to be next to each other. Strictly increasing means every kept element is larger than the one before it, so equal values cannot both be used.

Function

lengthOfLIS(nums: int[]) → int

Examples

Example 1

nums = [6,1,8,3,9,4,12,5]return = 4

The subsequences [1, 3, 4, 5] and [1, 8, 9, 12] both strictly increase and have length 4. No longer one exists: the array splits into the neighbouring pairs (6, 1), (8, 3), (9, 4) and (12, 5), and in each pair the larger value comes first, so an increasing subsequence can use at most one value from each pair. The answer is 4.

Example 2

nums = [7,7,7,7]return = 1

The values must strictly increase, so two equal values cannot both be used. The answer is 1.

Example 3

nums = [4,-1,0,3,-5,2,3]return = 4

The subsequence [-1, 0, 2, 3] uses the values at indices 1, 2, 5, 6 and strictly increases, so the answer is 4. The elements do not have to be next to each other.

Constraints

  • 1 <= nums.length <= 2500
  • -10^4 <= nums[i] <= 10^4

More ByteDance problems

  • Binary Tree Target-Sum PathsPHONE SCREEN · Seen Nov 2026
  • Alien DictionaryPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lexicographically Smallest Topological OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
All ByteDance interview questionsSee ByteDance hiring insights
Saved
class Solution {
    public int lengthOfLIS(int[] nums) {
        // Write your code here.
    }
}
Checking account…