coding
eBay
Amazon
Microsoft

eBay Coding Question: Increasing Triplet Subsequence

Topics:
Two Pointers
Greedy
Arrays
Roles:
Software Engineer
Backend Engineer
Full Stack Engineer
Experience:
Entry Level
Mid Level
Senior

Question Description

Problem summary

You are given an array of integers and must determine whether there exists a strictly increasing subsequence of length three: indices i < j < k with nums[i] < nums[j] < nums[k]. The comparisons are strict and indices must be increasing.

What you'll be asked to do

In an interview you will typically (a) explain a correct approach, (b) implement it (Python signature provided), and (c) analyze time/space complexity and edge cases. A common expectation is an O(n) solution with O(1) extra space using greedy/two-pointer ideas, but you should be able to discuss the O(n log n) LIS approach as well.

High-level solution (what to understand)

Maintain two variables (first, second) representing the smallest possible first and second elements of a candidate increasing pair. Iterate once over nums: update first when you find a smaller value, update second when you find a value larger than first but smaller than second, and return true as soon as you find a value greater than second (the third element). This demonstrates greedy reasoning and careful invariant maintenance.

Interview flow & skill signals

You will be judged on: correct handling of duplicates and edge cases (short arrays), explanation of invariants, time/space trade-offs, and ability to generalize (LIS or length-k subsequences). Expect follow-ups asking for indices, counts, or a streaming variant. Be prepared to walk through example arrays and give complexity: O(n) time, O(1) extra space for the greedy method.

Tips

Explain why the greedy choice keeps opportunities open for a valid triplet, test with arrays that include repeats, decreasing sequences, and large inputs, and mention alternative LIS-based solutions when asked about generalization.

Common Follow-up Questions

  • How would you modify the approach to return the actual indices i, j, k of a found increasing triplet?
  • Generalize the solution: how do you detect an increasing subsequence of length k efficiently (discuss O(n log k) approaches)?
  • How would you count the number of strictly increasing triplets in the array (trade-offs and complexity)?
  • How does the algorithm change if comparisons are non-strict (non-decreasing subsequence) or if duplicates are frequent?

Related Questions

1Longest Increasing Subsequence (LIS) — patience sorting and O(n log n) solution
2Find if an increasing pair exists (length-2 subsequence) — simplest greedy variants
3132 Pattern detection — related ordering and pattern constraints
4Detect increasing subsequence of size k — generalization and complexity

Explore More Questions

Practice This Question with AI

Get real-time hints, detailed requirements, and insightful analysis of the question.

Increasing Triplet Subsequence - eBay Coding Question | Voker