HackerRank: Staircase

Thank you for visiting this post! Be sure to also take a look at my other work on LinkedIn, Github, and my website.

Picture this scenario for me. You move into this AMAZING house. It’s great, it’s beautiful, it’s…wait is that a staircase?

Oh, no. You’ve never walked on stairs before….why? You never got around to learning it — shhhh just go with it.

Anywho, let’s learn how to conquer stairs via code!


Please click the link below to view the Problem Statement


I setup variables and counters for both the spaces and the string element they want us to use. Then I setup a basic for loop: the spaceCount would decrease and the hashTagCount would increase every time it looped through n.

Pretty simple, right? Is there a faster way we can do this though?

SO glad you asked!

My colleague from my study group, Genius Ben we call him, came up with this SUPER amazing solution.

The padStart() method pads the current string with another string (multiple times, if needed) until the resulting string reaches the given length. The padding is applied from the start of the current string.

-MDN Web Docs

Check it out:

Using padStart(), he sets the padding to the amount of n , which is 6, right from the start. He then sets his conditional to loop until “i” is less than or equal to n(6), and every time it repeats, it list’s a ‘#’ in place of the space.

WHAT!? I didn’t even know that padStart() was a thing. That’s the amazing thing about being a developer. You NEVER stop learning!


Thank you so much for stopping by! Starting next Monday, I will begin learning Java. Stay tuned for more Algorithm Content. Java Style!

Please checkout my online portfolio and feel free to connect with me on Linkedin!




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Building a Docker Container Orchestrator with Akka

We chose Ember in 2015 and it is still a good decision in 2020

Ember & Phorest logos connected with a plus symbol

Laravel Validation Guide: Methods, Rules & Custom Messages

Laravel Validation Guide — Flatlogic Blog

Pair Programming: Team Work Makes the Dream Work

CPP — Setting Up Environment

Multi-cloud maturity model

How to embed code in medium

Monitoring CO2 using AirCO2ntrol Mini

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Stephanie Segura

Stephanie Segura

More from Medium

Java Equals() and HashCode()

From Teacher to Software Developer

Need of Different Sorting Techniques