Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Background: Imagine we are building stairs out of small bricks. For the first step, we use one brick. For the second step, we stack 2

Background: Imagine we are building stairs out of small bricks. For the first step, we use one brick. For the second step, we stack 2 bricks. And for the third step, we stack 3 bricks. And so on.
With this in mind, write the function numberOfBricks(steps), which takes a non-negative integer number of steps, and returns the number of bricks that are required to create that many steps.
For example numberOfBricks(3) returns 6, which is 1+2+3.
Hint: The sum from 1 to n is called the nth triangular number. Here is a helpful formula to calculate the nth triangular number:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions