(Hackerrank) Day 0: Hello, World

As a fledgling Software Engineer, I’m discovering it truly pays to be curious, instead of leap frogging over important tech milestones. Of course, you can take it to an extreme, chasing one topic after another until you’re deep in the rabbit hole. But if you use your curiosity strategically, it pays off in dividends as you grow your programming skills.

Fledgling, leap frog, rabbit hole… enough with the animal references. I’ll just give you an example. It’s common knowledge in the tech world that practicing tech challenges on coding platforms (like Hackerrank, Leetcode, Codewars, etc.) will improve logical thinking and by extension coding ability. Yet many newly minted Software Engineers skip this endeavor and pour all of their efforts into job hunting, believing that the skills they currently possess will be enough to land a position in tech.

Many discover this isn’t the case. They’re competing against peers who were curious enough to check out coding platforms and use them to sharpen their skills. Additionally, these competitors are now familiar with the very platform that employers often use in their hiring process. So instead of spending their precious time trying to figure out how the platform actually works, they can dive right into solving the tech challenge. While the less demonstrably curious job seekers, who skipped the code challenges, waste valuable time trying to learn how to navigate the platform, leaving them less time to work on the actual tech challenge.

So what kind of programmer will you be?

I’m assuming the kind that uses their curiosity strategically, so in this blog I’m introducing Hackerrank, a coding platform that some employers use to conduct their tech challenges. Go to the Hackerrank website (https://www.hackerrank.com) and sign up to create an account so you can practice their challenges for free.

Side note, that’s one of the amazing things I’ve found since entering the tech field. It offers so many amazing learning tools, for FREE!

I found a great collection of challenges to help familiarize beginners with the platform & sharpen skills. It’s called 30 Days of Code. And it’s actually fun! It’s designed to resemble gaming. As you complete challenges, you’re eligible to unlock badges, track your skill accomplishments, see your ranking compared to others, etc. It’s incredible! Not to mention there’s also a tech community there you can engage with for help solving challenges, tech support, or to network.

30 Days of Code is designed to give you a coding challenge each day for thirty days straight. There are video tutorials that give a brief lesson on the targeted skill covered in the challenge. There’s a warm up lesson called Day 0: Hello, World. This challenge is a tech tradition in introducing new technology. The first thing you learn is how to output Hello World. This is a low level entry point into new tech that enables the user to get started with the basics and it also ensures that the tech is functioning properly.

So let’s tackle Day 0: Hello, World together. On the webpage, Day 0: Hello, World, beneath the heading are 6 tabs. The first tab, Problem, contains instructions on the challenge. The next tab, Submissions, will list all attempts at solving that you submitted. Leaderboard, shows the ranks, country, and coding language used for each user who submitted this challenge. Discussions is a convenient way to engage the community regarding any issues related to this challenge. Editorial gives you more insight and guidance into this challenge. It even gives the solution in several different coding languages. But no peeking! Tutorial usually holds a video lesson covering the skill subject of the challenge. However, the video is unavailable for this challenge.

Click the Problem tab and read through the challenge. The Objective gives an overview of the challenge which is basically learning how to use the platform by reading input and writing output. Task instructs on how to achieve the Objective, print Hello, World on one line and then save input in a variable and print the value of that variable on a second line. Note informs us on how to use their editor to select a coding language of choice. Input Format says our input is inputString so this is the variable that will store the input. Output Format succinctly reminds us we’ll be printing Hello, World on the first line and the contents of inputString (our variable value) on the second line. Then the Sample Input & Output demonstrates what’s expected to happen. Explanation explains the outcome of the previous Sample Input & Output.

Let’s code!

Scroll down to the editor and we see they’ve provided us with some starter code, a function named processData. The Language tab just above allows us to select the coding language of choice, mine is JavaScript so I make that selection, so select your preference.

The editor has numbers running down the left side. Just below the function’s closing curly bracket } there’s a greater than sign or angle bracket >, click it. It reveals some behind the scenes code that we’re prevented from editing. We don’t have to worry about this, it’s just code that allows the function to be run and tested properly when we click the Run Code button located just below the editor.

Back up to the processData function. On line 1, we see that our inputString is being passed in which makes it available for us to print out. Line 2 has commented out instructions. We use // to comment out text that we don’t want to actually run so this can be used to give notes or instructions. The commented out instructions claim the code in line 3 will print out on the first line. Let’s stop there so we can see this in action. Scroll down to the Run Code button, just beneath the editor, and click it.

The result is a big red Wrong Answer with a sad face. The Compiler Message repeats that we have the Wrong Answer. Input(stdin) tells us that “Welcome to 30 Days of Code!” was passed into the processData function for inputString. Your Output(stdout) shows that our function actually printed out Hello, World as intended. And Expected Output shows what the function was supposed to output in order to pass the test. Our output is missing Welcome to 30 Days of Code!

Back up to the processData function again. We have enough information to solve this challenge. The console.log(“Hello, World.”); is responsible for printing Hello, World. So now we have to write code that prints Welcome to 30 Days of Code! when it’s passed into the function. If we follow the Hello, World example, our code would be:
console.log(“Welcome to 30 Days of Code!”)

Click the Run Code button and… we pass! We’re congratulated for passing. We see that our output matches the expected output.

Now let’s submit our code by clicking the Submit Code button located next to the Run Code button. Oh no! We did not pass all of the Sample Test cases. That’s because our code is hard coded. The challenge is to make it dynamic which would enable it to print out different messages.

Back up to the processData function for the final time. This function is passing in the inputString for a reason. It will hold the different messages that will be printed out on the second line. So let’s refactor or change our code to:
console.log(inputString)

Notice we don’t wrap inputSting in quotation marks. That’s because it’s a variable. We wrapped Hello, World and Welcome to 30 Days of Code! in quotation marks because they are strings.

Click the RunCode button and… it works! Click the Submit Code button and… we did it! We passed all the tests! We completed our first Hackerrank challenge.

Now you can check your status on the Leaderboard or help out others in the community in the Discussions tab. Or you can move on to the next challenge by clicking the Next Challenge button on the green Congratulations bar.

However, remember I started this blog off talking about the benefits of being curious. In that spirit, I suggest you revisit the editor and click on the angle bracket tab, beneath the processData function, to reveal the behind the scenes code. Figure out how that code works. It’s going to pay off… in dividends.

--

--

--

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

Recommended from Medium

Dependency Tracking as a best practice for tag management — Magic Pixel

ML Based 3-Stage Document Verification and Validation System using AWS

How to Use RingCentral’s Nomadic E911 Feature

Simplifying Problem Solving

Reality Chain Update Log 0.9.6

Coupling as a Fitness Function in evolutionary architectures

Using Nix in Elixir projects

Comparing Azure ARM and Terraform

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
Wendy Raven McNair

Wendy Raven McNair

More from Medium

URL Slug — Everything You Need to Know

From RDBMS to Non-Relational Databases

How to Hire Full Stack Developers: What You Need to Know

What is an API?