PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/TikTok

Compute length of longest increasing subsequence

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of subsequences, dynamic programming and algorithmic optimization for array processing, and is categorized under Coding & Algorithms; it emphasizes practical application of algorithm design and complexity analysis rather than purely theoretical knowledge.

  • medium
  • TikTok
  • Coding & Algorithms
  • Software Engineer

Compute length of longest increasing subsequence

Company: TikTok

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given an integer array `nums` of length `n`. A **subsequence** of `nums` is a sequence that can be derived from `nums` by deleting zero or more elements without changing the order of the remaining elements. The elements of the subsequence do **not** need to be contiguous in the original array. A subsequence is called **strictly increasing** if every element is strictly greater than the previous one. **Task**: Return the length of the longest strictly increasing subsequence of `nums`. --- ### Example 1 Input: ```text nums = [10, 9, 2, 5, 3, 7, 101, 18] ``` One longest strictly increasing subsequence is `[2, 3, 7, 101]`, so the answer is `4`. Output: ```text 4 ``` ### Example 2 Input: ```text nums = [0, 1, 0, 3, 2, 3] ``` One longest strictly increasing subsequence is `[0, 1, 2, 3]`, so the answer is `4`. Output: ```text 4 ``` ### Example 3 Input: ```text nums = [7, 7, 7, 7] ``` Every strictly increasing subsequence has length `1` (any single element), so the answer is `1`. Output: ```text 1 ``` --- ### Constraints - `1 <= n <= 2 * 10^5` - `-10^9 <= nums[i] <= 10^9` Design an algorithm that can handle the largest constraint efficiently.

Quick Answer: This question evaluates understanding of subsequences, dynamic programming and algorithmic optimization for array processing, and is categorized under Coding & Algorithms; it emphasizes practical application of algorithm design and complexity analysis rather than purely theoretical knowledge.

Related Interview Questions

  • Parse a nested list from a string - TikTok (medium)
  • Implement stacks, streaming median, and upward path sum - TikTok (easy)
  • Maximize sum with no adjacent elements - TikTok (medium)
  • Implement stack variants and path-sum check - TikTok (medium)
  • Find the longest palindromic substring - TikTok (easy)
TikTok logo
TikTok
Dec 10, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
4
0

You are given an integer array nums of length n.

A subsequence of nums is a sequence that can be derived from nums by deleting zero or more elements without changing the order of the remaining elements. The elements of the subsequence do not need to be contiguous in the original array.

A subsequence is called strictly increasing if every element is strictly greater than the previous one.

Task: Return the length of the longest strictly increasing subsequence of nums.

Example 1

Input:

nums = [10, 9, 2, 5, 3, 7, 101, 18]

One longest strictly increasing subsequence is [2, 3, 7, 101], so the answer is 4.

Output:

4

Example 2

Input:

nums = [0, 1, 0, 3, 2, 3]

One longest strictly increasing subsequence is [0, 1, 2, 3], so the answer is 4.

Output:

4

Example 3

Input:

nums = [7, 7, 7, 7]

Every strictly increasing subsequence has length 1 (any single element), so the answer is 1.

Output:

1

Constraints

  • 1 <= n <= 2 * 10^5
  • -10^9 <= nums[i] <= 10^9

Design an algorithm that can handle the largest constraint efficiently.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More TikTok•More Software Engineer•TikTok Software Engineer•TikTok Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.