DEV Community

Cover image for Solve a problem is only a start
Razielini
Razielini

Posted on

2

Solve a problem is only a start

In the lasts few weeks, I have been solving some challenges at HackerRank, starting with the basics, in my mind I do not need to solve these challenges because there are so basic, and I'm right for the wrongs reasons.

It's not only about bringing the right solution and pass the tests, the way you solve the problem is important. Some of these simple challenges could have a hidden complexity depends on the solution you bring.

For example, the challenge Find Digits if you are interested to take some minutes reading, and try to solve it, I'm pretty sure not take higher than 10 minutes to solve, is basically there are free points in the platform.

If you solved the last challenge, maybe your solution was to transform the number to some type of iterable object, later iterate the object and evaluate every digit, its correct, it's a viable solution and even an optimal solution in a lot of cases.

But I'm sure is the most common solution you can find, another solution more uncommon o slightly complex is a solution with a Mathematical focus, for example:

function findDigits(n) {
  let result = 0;
  const copyN = n;
  while(n != 0) {
    if(n%10 != 0 && (copyN%(n%10) === 0)) result++
    n = parseInt(n/10);
  }
  return result;
}
Enter fullscreen mode Exit fullscreen mode

This code is the solution for the same problem, with some advantages like better portability between languages and performance.

This is what I was talking about at the start of the post when I said 'im right but for the wrong reasons', exist a lot of ways to solve a problem and all solutions can work, but some are better than others, and in some cases, we don't looking for because we don't know they exist.

As a software developer, I consider it very important to feel uncomfortable when things work well, I must try to improve the solution at least for a hobby.

If you have some years as a software developer and don't solve the challenge, I think you must start immediately with some easiest challenges, this is good to improve your logic and very common on job interviews, this can give you the advantage to get that role you are looking for or negotiate a better salary.

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

πŸ‘‹ Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay