FastPrepLongest Increasing Subsequence
Problems/Longest Increasing Subsequence

Longest Increasing Subsequence

Shopify logoShopify● MediumINTERNOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names a longest increasing subsequence task but gives no examples or interface. This length-returning version matches the reported core at about 85%; its empty-input rule and bounds are practice assumptions.

Given an integer array nums, find its longest strictly increasing subsequence. A subsequence keeps the original order but may skip elements.

For this exercise, assume you return the length of that subsequence. Equal values do not extend it, and an empty array has answer 0.

Function

lengthOfLIS(nums: int[]) → int

Examples

Example 1

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

The values [2,3,7,18] form a strictly increasing subsequence of length 4. No subsequence of length 5 exists.

Example 2

nums = [2,2,2]return = 1

Any single value forms an increasing subsequence. Equal values cannot extend it, so the answer is 1.

Constraints

  • 0 <= nums.length <= 20000
  • -10^9 <= nums[i] <= 10^9

More Shopify problems

  • Deterministic Secret Santa AssignmentPHONE SCREEN · Seen Oct 2026
  • Mars Rover Robot ControllerPHONE SCREEN · Seen Oct 2026
  • Choose Items for a BackpackOA · Seen May 2026
All Shopify interview questionsSee Shopify hiring insights
Saved
public int lengthOfLIS(int[] nums) {
    // Return the longest strictly increasing subsequence length.
}
Checking account…