Solving The Steps Algorithm Problem

Bryam Vicente
2 min readJul 27, 2021

For this blog, I’ll be going over an algorithm problem in which we have to console log # which demonstrates a step. Here’s a screenshot of the prompt:

Console logging # depends on the input that you provide. The examples from the screenshot above do a great job at showing what the input and output values should be for this problem. If our input is 4 then this is what the output should be:

##########

In this case, we can look at the output as some form of table with rows and columns. If we look at the example inputs, notice that there are empty spaces inside the string until the string if full of #.

The easiest way to solve this problem is through a brute force (O(n²)) solution. We’ll need to create a for loop that iterates over the rows and another that can iterate over the columns. Here’s a screenshot of my pseudo code:

Here’s a screenshot of my solution:

Here are the results from the examples on lines 37 -38:

For more info on for loops please check the resource section below!

Resources:

--

--