FastPrepLongest Increasing Price Subsequence
Problems/Longest Increasing Price Subsequence

Longest Increasing Price Subsequence

OpenAI logoOpenAI● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an OpenAI online assessment for new grads. Earlier community evidence described increasing recorded prices. A later screenshot of the task gives chronological monthly net profits, allows skipped months, returns the length of the increasing subsequence, and gives the signed example [-1,9,0,8,-5,6,-24]. Its longest_profit(data) interface maps to the existing lengthOfLIS(prices) function. The old parameter name does not limit values to positive prices. The report discusses a size of 1,000, while our limit remains 2,500. We chose the signed number limits.

Our version is about 97% the same as the reported question.

Special thanks: 🌷 A special thank you to our lovely, amazing frenz who shared that this question appeared again on October 10, 2026! ◝(ᵔᗜᵔ)◜ 🩵

You are given an integer array prices containing financial values in chronological order. The values can represent recorded prices or consecutive monthly net profits; net profits may be negative or zero. Return the maximum number of values you can select so that the selected values are strictly increasing.

The selected values must keep their original order, but they do not need to be adjacent. In other words, find the length of the longest strictly increasing subsequence of prices.

  • You may skip any number of positions.
  • Every selected value after the first must be greater than the previously selected value. Equal values cannot extend the subsequence.
  • Return only the length of the subsequence.

Function

lengthOfLIS(prices: int[]) → int

Examples

Example 1

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

One longest strictly increasing subsequence is [2, 3, 7, 18]. Its elements occur in their original order, and its length is 4.

Example 2

prices = [4,10,4,3,8,9]return = 3

Select [4, 8, 9], skipping the intervening prices. No strictly increasing subsequence of length 4 exists, so the answer is 3.

Example 3

prices = [7,7,7]return = 1

All prices are equal. A strictly increasing subsequence can select only one of them.

Example 4

prices = [-1,9,0,8,-5,6,-24]return = 3

These are monthly net profits. Select [-1, 0, 6] in chronological order, skipping intervening months. Its length is 3, and no strictly increasing subsequence of length 4 exists.

Constraints

  • For this exercise, assume 1 <= prices.length <= 2500.
  • For this exercise, assume every value is an integer and -10^9 <= prices[i] <= 10^9.

More OpenAI Online Assessment questions

  • Count Routes Through Four Shop TypesOA · Seen Oct 2026
  • Digit-Sum Sequence Join PointOA · Seen Oct 2026
  • Network Endpoint or Cycle BoundaryOA · PHONE SCREEN · Seen Oct 2026
  • Password Clues and the Next CommandOA · Seen Oct 2026
  • Macaron Order PriceOA · Seen Oct 2026
  • Shortest Atom Action PathOA · Seen Oct 2026
  • Simplify a Quadratic ExpressionOA · Seen Oct 2026
  • Minimum-Cost Color SequenceOA · PHONE SCREEN · Seen Oct 2026
  • Largest Microorganism After ConsumptionOA · Seen Oct 2026
  • Invert or Blur an ImageOA · Seen Sep 2026

Similar questions at other companies

  • Minimum Cost to Attend Required CoursesVisa · OAVisa interview questions
  • Fill a Time Window with SongsMicrosoft · OAMicrosoft interview questions
  • Maximum Taxi EarningsWells Fargo · OAWells Fargo interview questions
  • Longest Increasing Subsequence from Two ArraysSquarepoint Capital · OASquarepoint Capital interview questions
  • Split Array Largest SumLinkedIn · OALinkedIn interview questions
  • Longest Increasing SubsequenceAtlassian · OAAtlassian interview questions
  • Maximum Profit from an Increasing Price TripletOdoo · OAOdoo interview questions
  • Longest Increasing Subsequence LengthApple · OAApple interview questions
  • Beautiful RowNutanix · OANutanix interview questions
  • Split Array to Minimize the Largest SumInfosys · OAInfosys interview questions

Interview reports that mention this question

  • OpenAI OA: What It Tests (2026)
All OpenAI interview questionsSee OpenAI hiring insights
Saved
class Solution {
    public int lengthOfLIS(int[] prices) {
        // Write your code here.
    }

}
Checking account…