Pascal's Triangle
Reported by candidates from Ericsson's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Ericsson's May 2026 OA includes Pascal's Triangle, a classic array construction problem that looks harder than it is. You're building a 2D array where each element is the sum of two elements from the row above. The pattern is straightforward: initialize each row with 1s at the edges, fill the middle by adding adjacent pairs from the previous row, and return all rows. This is a warm-up problem designed to pass, not trip you. If you blank during the live OA, StealthCoder will spot the recurrence relation instantly and feed you the structure.
The problem
Complete the function below. The function receives the number of rows and returns the generated Pascal's Triangle. Problem Problem: Pascal's Triangle Given a non-negative integer numRows, generate the first numRows rows of Pascal's Triangle and return them as a 2D array triangle. Pascal's Triangle is defined as: Row i (0-indexed) contains i+1 elements. The first and last element of each row is 1. For other positions: triangle[i][j] = triangle[i-1][j-1] + triangle[i-1][j] for 0 < j < i. Input A single integer: numRows Output Print a 2D array (you may print each row as a list) representing the first numRows rows. Constraints 0 <= numRows <= 30 Example Input: 5 Output: [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] Example Input 0 Output [] Function Description Complete solvePascalsTriangle. It has one parameter, int numRows. Return the first numRows rows of Pascal's Triangle as a 2D integer array. The returned string array must match the expected standard output lines for the sample input. Use the limits and requirements stated in the prompt.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Pascal's Triangle is a dynamic-programming building problem, but don't overthink it. You iterate from row 0 to numRows-1. For each row i, you create a list of i+1 elements. Set the first and last to 1. For positions 1 to i-1, access the previous row and sum triangle[i-1][j-1] + triangle[i-1][j]. Edge case: if numRows is 0, return an empty 2D array. Time is O(numRows squared), space is O(numRows squared) for the output. This is not a trick question. The most common mistake is an off-by-one error in indexing or forgetting the boundary conditions. Have your base case clear before you code. During the live OA, if you freeze on the recurrence formula, StealthCoder will show you the exact lookup pattern.
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 Pascal's Triangle 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
This OA pattern shows up on LeetCode as pascals triangle. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Ericsson's OA.
Ericsson 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.
Pascal's Triangle FAQ
Is this problem actually easy or does Ericsson hide a twist?+
It's genuinely straightforward. The definition is given in the problem. No bit manipulation, no graph stuff, no hidden edge case. The twist, if any, is that you must handle numRows=0 and return an empty array. That's it. Don't invent complexity.
What's the fastest way to code this in 2-3 minutes?+
Start with an outer loop from 0 to numRows. For each iteration, create a new row. Set first and last to 1. Loop j from 1 to i-1 and compute triangle[i-1][j-1] + triangle[i-1][j]. Append and move. Pseudocode before typing saves time.
Do I need to optimize space or is O(numRows squared) fine?+
You're returning a 2D array, so you can't reduce output space. O(numRows squared) is expected and acceptable. No fancy space-optimized version required. Just build it clean.
What languages is this tested in at Ericsson?+
The problem statement doesn't specify, but Pascal's Triangle is language-agnostic. Python, Java, C++, JavaScript all work identically. Use whatever you're comfortable with. The logic is the same.
If I blank on the recurrence formula during the OA, what do I do?+
Write out the first three rows by hand and see the pattern. Row 0 is [1]. Row 1 is [1,1]. Row 2 is [1,2,1]. You'll see 2 = 1+1. That's your formula. Reverse-engineer it if you need to.