The stack of apples can be imagined as shown below. For every row, there is an increase of 1 apple from the previous row.
This means that the sum total of the apples present in the stack will be sum of AP given as : 1,2,3,4.... ie the sum of numbers from 1.
This is given by the formula S = $$\frac{n \times (n+1)}{2}$$
Since the initial number of apples was not more than 150, we find the maximum number of rows that was possible.
Let S be the total initial sum of apples in the cart.
We know that $$S\leq 150 $$
$$ \Rightarrow \frac{n \times (n+1)}{2} \leq 150 $$
$$ \Rightarrow n \times (n+1) \leq 300 $$
$$ \Rightarrow n^2 + n \leq 300 $$
Since the biggest number with square less than 300 is 17, we try to see if 17 works in the expression by hit and trial method.
So, 17 x 18 = 306 > 300, therefore the maximum number of rows possible is not 17.
Since 306 is JUST over 300, let us check at 16.
So, 16 x 17 = 272 < 300, therefore the maximum number of rows possible is 16.
Let us tabulate the total number of apples present in the cart based on the number of rows :
Since the total number of apples from row 15 is less than 126 (which was found by the customer), we can safely say that the total number of rows of apples with the shopkeeper that day was 16.
Now, if 'n' rows of apples are sold, the total available apples can be calculated as : $$\frac{16 \times 17}{2} - \frac{n \times (n+1)}{2}$$
Let us tabulate the result obtained in this case :
From the table we can see that when the customer saw 126 apples, the apples in the top 4 rows had been sold.
Therefore, the number of rows = 16 - 4 = 12 rows.