Reported July 2026
IBMdynamic programming

Count Strictly Increasing Subsequences of Length 3

Reported by candidates from IBM's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live IBM OA. Under 2s to a working solution.
Founder's read

n goes up to 5000, so the O(n^3) triple loop is dead on arrival. That's the whole point of this IBM OA question, reported in July 2026. You count strictly increasing subsequences of length 3 and return the result modulo 10^9 + 7. It looks like a counting problem, and it is. The trick is picking a middle element and counting what sits on each side. If you've got an invite in your inbox, learn this one shape and you're fine. StealthCoder is there as a safety net if your mind goes blank mid-assessment, but this one is very doable on your own.

The problem

Given an integer array arr of length n, return the number of strictly increasing subsequences of length 3, modulo 10^9 + 7.
A subsequence is obtained by deleting zero or more elements without changing the order of the remaining elements. A length-3 subsequence is strictly increasing when its indices satisfy i < j < k and its values satisfy arr[i] < arr[j] < arr[k].

Function
countIncreasingSubsequences(n: int, arr: int[]) → int

Examples
Example 1
n = 5
arr = [1, 2, 3, 4, 1]
return = 4
The strictly increasing subsequences are [1, 2, 3], [1, 2, 4], [1, 3, 4], and [2, 3, 4]. Therefore, the answer is 4.
Example 2
n = 4
arr = [3, 1, 4, 5]
return = 2
The two strictly increasing subsequences are [3, 4, 5] and [1, 4, 5].

Constraints
1 ≤ n ≤ 5000
0 ≤ arr[i] ≤ 10^9

Reported by candidates. Source: FastPrep

Pattern and pitfall

Fix the middle index j. Count how many i < j have arr[i] < arr[j], call it left. Count how many k > j have arr[k] > arr[j], call it right. Add left * right to the answer. Two nested loops per j gives O(n^2), which is about 25 million operations at n = 5000. That's fine. The common pitfalls are using <= instead of strict <, forgetting the modulo on the running sum, and overflow in languages with fixed-width ints, since left * right can reach about 6 million squared-ish products that add up fast. Take the mod after each multiplication and addition. Values go up to 10^9, so don't use values as array indices. A Fenwick tree with coordinate compression gets you O(n log n), but you don't need it here. If you freeze during the live OA, StealthCoder can hand you this middle-element approach as a hedge.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Count Strictly Increasing Subsequences of Length 3 cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass IBM's OA.

IBM reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Strictly Increasing Subsequences of Length 3 FAQ

What's the trick to the IBM increasing subsequences of length 3 problem?+

Stop enumerating triples. Treat each index as the middle of a triple. Count smaller elements to its left and larger elements to its right, then multiply those two counts. Sum across all middles, mod 10^9 + 7. That turns a cubic problem into a quadratic one.

Is O(n^2) fast enough with n up to 5000?+

Yes. Roughly 12.5 to 25 million simple comparisons depending on how you loop. That runs comfortably in any mainstream language. You only need a Fenwick tree if you want O(n log n), and the constraints don't force it.

Do I need coordinate compression?+

Only for the Fenwick tree approach, since values reach 10^9. With the O(n^2) middle-element method you just compare values directly, so no compression or value-indexed arrays are needed.

Where do people lose points on this one?+

Three spots: using non-strict comparisons so equal values get counted, skipping the modulo and overflowing, and miscounting by pairing the wrong side. Test with example 1, arr = [1,2,3,4,1], which must return 4, and with a case of all equal values, which must return 0.

How should I prepare in 48 hours for this OA?+

Write this solution from scratch twice. Then try the Fenwick tree version once. Also run a few edge cases by hand: n under 3, all equal values, and a strictly decreasing array. The counting-by-middle idea shows up in many similar problems, so it's worth getting it into your fingers.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with IBM.

OA at IBM?
Invisible during screen share
Get it