DEV Community

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

Posted on

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.

Top comments (0)