Distinct Products After Removing One Element
Reported by candidates from HSBC's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The HSBC OA reported in September 2026 looks like a big-number product problem, but it's really a distinct-values count in disguise. You've got an invite and maybe two days. Here's the read: product of everything divided by A[i] is the result of removing index i, so two removals match only when A[i] values match. The array can hold 100000 elements up to 1000000000, so building the products is a trap. If you blank on the reduction during the live assessment, StealthCoder is the quiet backup that reads the screen and hands you the approach.
The problem
You are given an array A of positive integers. Remove exactly one element and compute the product of all remaining elements. If removing different positions produces the same numerical product, count that product only once. When one element remains, its value is the product. Return the number of distinct products obtainable by removing exactly one element. The answer must be computed without constructing the potentially enormous products. Function solution(A: int[]) → int Examples Example 1 A = [9,16,4] return = 3 Removing 9, 16, or 4 gives products 64, 36, and 144, so there are 3 distinct products. Example 2 A = [3,4,2,3,1] return = 4 The two occurrences of 3 produce the same remaining product. Removing each of the other distinct values produces a different product, for 4 possibilities. Example 3 A = [1000000000,1000000000] return = 1 Either removal leaves the same single value, so only one product is obtainable. Constraints 2 <= A.length <= 100000 1 <= A[i] <= 1000000000
Reported by candidates. Source: FastPrep
Pattern and pitfall
Let P be the product of all elements. Removing index i gives P / A[i]. Since all values are positive, P is nonzero, so P / A[i] equals P / A[j] exactly when A[i] equals A[j]. Different values always give different products. So the answer is just the number of distinct values in A. Put the array in a set and return its size. That's O(n) time and never touches a huge number. Check it against the examples: [9,16,4] has 3 distinct values, giving 3. [3,4,2,3,1] has 4 distinct values, giving 4. [1e9,1e9] has 1, giving 1. The pitfall is computing the product with big integers or modular arithmetic. Modular hashing can collide and overflow breaks everything. Another pitfall is overthinking the single-element-left case, which is already covered. If the reduction slips away mid-assessment, StealthCoder is the hedge that shows you the set-size answer.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Distinct Products After Removing One Element 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass HSBC's OA.
HSBC reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Distinct Products After Removing One Element FAQ
What's the trick in the HSBC distinct products problem?+
Removing index i leaves P / A[i], where P is the total product. All values are positive, so two removals give the same product only if the removed values are equal. The answer is the count of distinct values in the array. No multiplication needed.
Do I need big integers or modulo for this?+
No. Big integers would be slow and modulo can create false collisions. The whole point is that you never build any product. A hash set of the values and its size is the full solution, and it sidesteps overflow entirely.
What's the time and space complexity?+
O(n) time and O(n) space with a hash set. Sorting and counting adjacent unique values also works at O(n log n) time with little extra space. With n up to 100000, either is comfortably fine.
How hard is this one really?+
Easy once you see the reduction, and the problem is built to hide it behind talk of huge products. The code is about three lines. The risk is spending your time on factorization or product hashing instead of stepping back.
How do I prepare for this in 48 hours?+
Practice spotting when a quantity like total divided by element depends only on the element. Then write the set solution and test the three given examples, including the two-equal-elements case. Also try arrays with a 1 in them to confirm nothing odd happens.