Geek Culture
Published in

Geek Culture

An Algorithmic Journey

I recently attended a presentation by Rahul Pandey and Alex Chiou where they explained why DS&A (data structures and algorithms) practice is important, as well as what to expect as you learn/practice algorithms. (You can find some take aways from that presentation here. I highly recommend connecting with them on LinkedIn and signing up for their Slack workspace and/or email blasts. Their presentations are absolute gold: equal parts humble/helpful/human.) SO much of what they said resonated with me. I particularly appreciated their diagram below.

The Standard Algo Journey as Described by A Couple Of True Algo Jedis Who Happen To Be The Nicest Guys

I’ve been working daily on algorithms for a few months now. Some days are easier than others, for sure. What I didn’t expect was that once I started feeling like I knew a little bit of what I was doing and then ramped up to more complex/demanding algorithms, I would backslide right back into “I feel dumb”. This feeling was alarming but the cycle does make sense: the more we challenge ourselves by stepping outside of our comfort zones, the more we test our skills… and the more we may doubt our abilities.

Personally one of the aspects of this journey that I am the MOST appreciative of are my Flatiron friends/colleagues who are struggling/stretching through this journey with me practically every morning. While I am thrilled at those times when I am able to show off a solution and help to explain or clarify an issue for a friend, I find myself more and more often being the person who needs more clarification. It is humbling to be sure. I remind myself to be patient and kind - to myself. (Being patient and kind has usually come naturally to me when it comes to working with others, if I do say so myself!) Most of us don’t become “good at algos” over the course of a few weeks or months, but it most certainly is worth the trials and tribulations to keep on working at it. Boy is it invigorating, even joyful, when you learn a new concept/figure something out and it works! With this in mind I want to take you through a recent algorithm that I struggled with. When I got it working I practically danced in my seat!

This problem is called Human Readable Time (Kata/level 5 on Codewars).* Here are the instructions and a few examples below:

Human Readable Time, Codewars

My first thought was “I don’t know how to do this”. Ohhh, that “I feel dumb” sentiment is powerful! I then decided that I would want to iterate through the number somehow to get my hours, minutes, numbers. But numbers aren’t iterable the same way strings or arrays are... I also knew that padStart() would come in handy. (PadStart allows us to add/pad string character(s) to the beginning of another string and it is a different animal than your standard string interpolation. PadStart takes two arguments: the intended length of the string and the character to be added, whether it is “***” or “00” or “…………..”) So after staring at the problem for awhile, here was a stab at some pseudo code:

I had recently seen/used other examples of a combination of divide (“/”) and modulo (“%”) to break down numbers. So I decided to try it here: if we have 61 seconds and break our seconds out like so: minutes = Math.floor(61 / 60), and seconds = 61 % 60, we’ll have one minute and a remainder of one second. I prefer to use very simple solutions when testing out math concepts to make sure my mind is wrapping around the question and the accurate solution. I use the Chrome dev tools console and MDN repls to test out my assumptions.

testing assumptions with Chrome dev tools
Thank you MDN for embedding repls in so many of your webpages!

I started placing some variables in my code and console.logged.

Note that my assumptions were a little bit off, above. My hours were accurate but my minutes were actually returning seconds. I just needed to tweak a little bit of the math.

I finished out my variables, made a couple of adjustments, continued to test my assumptions, and got some green checks!!! Hey, some of this makes sense now!! This may not be the sexiest solution but it is readable and it makes me feel smart. My first Kata 5!

Working Solution for Human Readable Time

*Note I had to convert hours/minutes/updatedSeconds to strings before using .padStart() because you can’t coerce a number into a string while using padStart.

This Green Response Makes Me So Happy

I highly recommend joining a group of people with whom you trust to succeed/fail, and practice daily if you can. Someday we’ll all be algo jedi masters!!

Consult the docs…. check your assumptions….

*Codewars is a terrific place to begin learning algorithms. The easiest problems are Kata (level) 8 and they become more and more challenging as the Kata numbers decrease. The easiest Codewars problems are infinitely easier than “Easy” Leetcode and Binary Search problems. It is important to practice on Leetcode and Binary Search (along with other code challenge platforms) but when you’re just starting, trust me, you want to log a bunch of “wins”.



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