This text provides seven tips for improving coding speed and efficiency in Python challenges on HackerRank.
Abstract
The author shares their experience and tips for improving Python skills on HackerRank, focusing on seven key strategies to boost coding speed and efficiency. These tips include starting with easy challenges, gradually increasing difficulty, recording and reapplying techniques, reading discussions, not getting too attached to one-liners, using the provided code as a starting point, using Hackos to unlock test cases, enabling Vim or Emacs mode, and taking the test after clearing challenges. The author encourages readers to embrace failures as opportunities for growth and learning.
Bullet points
Start with easy challenges and gradually increase difficulty.
Record successful techniques and reapply them to new challenges.
Read discussions to learn from others' solutions and explanations.
Avoid getting too attached to one-liners and focus on readability.
Use the provided code as a starting point, but think freely and explore alternative solutions.
Use Hackos to unlock test cases and better debug code.
Enable Vim or Emacs mode for a more efficient coding experience.
Take the test after clearing challenges for a chance to earn a certification badge.
Embrace failures as opportunities for growth and learning.
7 Tips I Wish I Knew Before Clearing All HackerRank Python Challenges
That will boost your coding speed and efficiency
When you code, be like water. — Photo by author
I recently published a piece about how I cleared all HackerRank SQL challenges in two weeks. It was a fun ride, and there’s no reason not to ride on the momentum and brush up my Python skills. So here I am, three weeks later, writing this article sharing my experience and tips with you on what I’ve learned from the journey. There will be no code in this article, so worry not even if you know squat about Python or Hackerrank. This article will share seven tips that I wish I know before I start doing Hackerrank challenges. This article is about Python challenges, yet it will also generalize to other languages and other competitive programming platforms. I hope you can learn a thing or two. Let’s jump right in!
Tip #1: Start Easy, and Gently Work Your Way Up
Like most other competitive programming platforms, HackerRank groups challenges into different difficulty levels. When you first start, the best way is to use the filters on the right side, start from the ‘Easy’ ones, then gradually work your way down the difficulty chain.
Photo by author
There are three difficulty levels:
Easy — These are essential syntaxes mastery and best practices questions. It helps you warm up and refresh your language knowledge, preparing you for more complex challenges. If you know the language well, you’ll blast through it pretty quickly, so clearing it first won’t waste much of your time. If you find some of the ‘Easy’ problems actually hard to solve, then it’s time to go back to your basic language training ground and brush up. Otherwise, you’ll find some ‘Medium’ or ‘Hard’ challenges impossible to solve later on.
Medium — these challenges usually require you to put multiple pieces together to solve. Maybe string manipulation plus list comprehension, or regex plus Collections data structures, etc. After finishing these questions, you’ll be able to pick the suitable data structure/class and make them work together to solve the problem.
Hard — There aren’t many of them, but they are the real meat. It requires you to put everything together, finding the optimum solution within the time/space limitation. Certain problems need specific algorithms to be solved, but algorithms are not the focus for Python-specific problems. The challenges were created to help you improve Python skills, not data structure and algorithm skills. So they won’t be too hard to solve. Most ‘Hard’ problems, you won’t be able to brute force, though.
So the best strategy is to start from ‘Easy,’ master all pieces of the programming languages. Then practice your ability to put multiple ones together to solve the ‘Medium’ problems. Once you feel comfortable doing that, try to tackle the ‘Hard’ ones. This way, the learning curve won’t be too steep, and you are more likely to succeed without frustration or get stuck.
I called it the RRR approach. Record, reapply and repeat. Let me explain what that means.
Record
If you are doing language-specific challenges rather than doing algorithm or data structures problems, it’s pretty safe to assume that you are, to some extent, still learning the ropes. If this is you, then recording your success and failures along the way will benefit you a lot. The purpose of doing the challenges is still learning, and it involves taking notes, reflecting on what you’ve done right or wrong, analyzing the problem, spotting the patterns, etc. Try asking yourself quality questions like:
What is the problem trying to test you?
What techniques/data structures/syntax are used?
Is your solution the optimum one? Are there alternative approaches? How are those compared to your solution?
What is the most upvoted solution in the Discussion section? Why so? Could you integrate some of their technique into your solution and make it better?
Keeping a record of new tricks/snippets you learned while solving the problem will build up a snippets library along the way, which you can refer back to later. Building up a snippet library can save you more time doing later challenges and is also great for spaced repetition. If you are the organized type, you can assign problem type/pattern tags to your code snippets, so in the future, you can quickly go back and grab it to boost your problem-solving process. You can find my notes here��. It’s like a Go Joseki. A little bit of memory here goes a long way.
Better yet, you can share your codes on Github Gist, Twitter, or even LinkedIn, showing your progress while helping others. There are multiple benefits. Making your records public forces you to think more clearly, refactor your code more, and overall clearer thinking when doing the challenges. There is an excellent article about the benefit of ‘Learn In Public,’ which you might want to check out.
Reapply
Once you’ve recorded what you just learned, reapply them as much as possible when doing new challenges. Strive to make what you learned your second nature. This is especially easy to achieve while you are steamrolling through all challenges in a relatively short time. You close the loop by practicing what you’ve learned, deepening your understanding, and using those novel/foreign techniques and ideas like breathing.
Repeat
Repeat steps 1 and 2. You will find yourself learning new things while practicing them, spotting more patterns, and adding the optimum solutions to your code arsenal.
The sun rises and falls, and you blast through challenges after challenges, keyboard clicking, a smirk on your face, mind like water. This is growing, my friend. This is how growing looks like.
Tip #3: Read the Discussions, but Don’t Get Too Addicted to One-Liners
The discussion section probably is where most learning happens for me in Hackerrank. Here you can check other people’s solutions as well as their rationales. The community in Hackerrank is friendly, open, and helpful. People usually answer questions on why they approach particular challenges the way they do, with code snippets and links to good resources. So don’t ignore the discussion, EVEN IF YOU ALREADY CRACKED THE CHALLENGE!
My usual routine is to try to solve the problem all by myself, brute force or not. This helps me gain a deeper understanding of the problem. Then head over to the discussion section and check other people’s solutions. I tried to understand the solution without peeking at their explanation. If I stuck, I’d then check the explanation. I can’t tell how many times I was wowed by the brilliant, beautiful, and elegant solutions other people came up with. I’ll usually take notes and try to apply those in my future challenges too.
There is a gotcha, though. The community tends to upvote those ‘sexy’ one-liners, even if they are hard to read. You might also want to do that in your solution. It makes you feel well. Don’t get too obsessed! Readability still trumps one-liners every day in the real world. Going to the other extreme of always trying to do one-liners will actually hurt your coding style.
Tip #4: When Stuck, Peak!
Most Upvoted Solution — Photo by author
Doing coding challenges, and you’ll inevitably encounter your ‘stuck’ moment. No matter how much time you spend, how many different things you throw at the problem, you still can’t find a way out. This is where the ’15 minutes’ rule comes into play:
Take 15 minutes to solve the problem any way you can. However, if you don’t have an answer after 15 minutes, you must ask someone.”
The truth is it’s not worth it to get stuck in a problem for more than 15 minutes, most of the time. Not all challenges are created equal. Some challenges are not well designed or elaborated(this is especially the issue Hackerrank mostly complained about). So don’t sweat them. Just head to the discussion section and look at other people’s solutions. Sometimes you’ll find others complaining about the vagueness of the question, and you’ll thank me for not wasting 1 hour of your precious time on a stupid question. 😏
Using your time on more important challenges is a better use of your time.
Tip #5: You Don’t Have to Use the Provided Code
Provided codes for the challenge — Photo by author
SSome challenges give you a lot of pre-written boilerplate codes and only leave one function for you to fill. This is usually helpful. You can focus on the problem to be solved instead of the ‘logistic codes’. Yet sometimes, I found the provided codes limiting my thinking. Some provided codes will import certain libraries for you, and if you use them, you’ll be solving the problem using them. However, the optimum solution might not use the libraries at all. And the problem is solvable with multiple approaches, and you are limited just using the provided libraries. So my suggestion is, well, you don’t have to follow the provided codes if you have better ideas. For example, the Time Delta challenge gives you re, os, math, random, sys, yet you don’t have to use any of them. The best way is just to use the DateTime lib or calendar lib.
Think freely, think out of the box.
Tip #6: Use Your Hackos, Don’t Skimp
Hackerrank Hackos Transaction— Photo by author
There is a virtual currency reward for solving challenges called Hackos in Hackerrank. Yet there aren’t many places you can use them. The biggest use is to unlock test cases of the challenges. Challenges use these test cases to judge whether you passed or not. Sometimes your solution work on part of the test cases but not all, and you can unlock those test cases that you fail and better debug your code. My advice: Don’t skimp your Hackos. There are not many uses for Hackos elsewhere anyway, so totally use it to unlock those test cases and accelerate your growth. Find out where you fall and solve the darn problem.
Tip #7: Enable Vim or Emacs Mode
This is for you vim or emacs enthusiasts. If you happen to be one, doing so will definitely improve your coding experience, if not your coding efficiency. Hackerrank’s code editor supports vim or emacs shortcuts. So if you code faster with these two apps, you should totally turn the switch on.
Hackerrank Coding Editor supports vim/emacs mode — Photo by author
Bonus: Take the test if you cleared the challenges. It will be a breeze!
Hackerrank Certificates — Photo by author
Hackerrank offers certifications in many languages and different levels. For Python, they only provide the ‘Basic’ level. So if you happen to have cleared all the challenges, then take the certification test by no means. It will be a breeze, and who doesn’t like a shiny badge on their profile for potential recruiters to see?
It took me three weeks to clear all Python challenges on Hackerrank. (A bit longer than the SQL challenges, I have another article talking about my SQL takes, you can check it out if interested.) The biggest takeaway for me is:
When You Are Failing, That’s Exactly When You are Growing.
The challenges I learned the most are the ones that took me the longest. Even applying the 15 minutes rule, I still had a hard time figuring out other people’s solutions, implementing them into my own, etc. I guess that’s because I’ve found the weakest spot of my knowledge?
When you are failing, that’s when your chance of real growth shows itself. Embrace it, cherish it, grab it, don’t fear it. Making it the stepping stone of your future success. Almost all successful people walk this path. Fail 99 times quickly and efficiently, then get to the final big success you deserve.
I hope you find this article enjoyable to read and learned a thing or two from it. If you want to know more about what I think, practice, and write about data science, consider signing up to become a Medium member. It’s $5 a month, giving you unlimited access to stories on Medium. If you sign up using my link, I’ll earn a small commission.