-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ad35ee
commit 0046270
Showing
4 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# buildStaircase | ||
|
||
Interview question of the [issue #318 of rendezvous with cassidoo](https://buttondown.email/cassidoo/archive/let-us-remember-that-our-voice-is-a-precious-gift/). | ||
|
||
## The Question | ||
|
||
**You have `n` equal-sized blocks and you want to build a staircase with them. Return the number of steps you can fully build.** | ||
|
||
Example: | ||
|
||
```js | ||
> buildStaircase(6) | ||
> 3 | ||
|
||
// # | ||
// ## | ||
// ### | ||
|
||
> buildStaircase(9) | ||
> 3 // it takes 10 blocks to make 4 steps | ||
``` | ||
|
||
## Installing & Running | ||
|
||
Just `pnpm i` to install all dependencies and then `pnpm t` to run the tests! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { buildStaircase } from './buildStaircase'; | ||
|
||
describe('#buildStaircase', () => { | ||
it('should return 0 for n equal to 0', () => { | ||
expect(buildStaircase(0)).toBe(0); | ||
}); | ||
|
||
it('should return 1 for n less than 3', () => { | ||
expect(buildStaircase(1)).toBe(1); | ||
expect(buildStaircase(2)).toBe(1); | ||
}); | ||
|
||
it('should return 2 for n less than 6', () => { | ||
expect(buildStaircase(3)).toBe(2); | ||
expect(buildStaircase(4)).toBe(2); | ||
expect(buildStaircase(5)).toBe(2); | ||
}); | ||
|
||
it('should return 3 for n less than 10', () => { | ||
expect(buildStaircase(6)).toBe(3); | ||
expect(buildStaircase(7)).toBe(3); | ||
expect(buildStaircase(8)).toBe(3); | ||
expect(buildStaircase(9)).toBe(3); | ||
}); | ||
|
||
it('should return 4 for n less than 15', () => { | ||
expect(buildStaircase(10)).toBe(4); | ||
expect(buildStaircase(11)).toBe(4); | ||
expect(buildStaircase(12)).toBe(4); | ||
expect(buildStaircase(13)).toBe(4); | ||
expect(buildStaircase(14)).toBe(4); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
You have `n` equal-sized blocks and you want to build a staircase with them. | ||
Return the number of steps you can fully build. | ||
Example: | ||
> buildStaircase(6) | ||
> 3 | ||
// # | ||
// ## | ||
// ### | ||
> buildStaircase(9) | ||
> 3 // it takes 10 blocks to make 4 steps | ||
*/ | ||
|
||
export function buildStaircase(n: number): number { | ||
let height = 2; | ||
while (n > 0) { | ||
n -= height; | ||
height++; | ||
} | ||
return height - 2; | ||
} |