Wrestling with Technical Challenges
indiejesus2
Posted on June 9, 2021
Last week, I was hoping I would move forward in the interview process and be able to show off my skills with a technical challenge. That unfortunately did not happen, but I did participate in two other technical challenges to be accepted into apprenticeship programs. The first one went okay, my biggest challenge was attempting to debug a function that would fail without knowing what parameters were causing it to break. I was not able to solve that one and the company moved on without me.
I completed my second technical challenge and boy what a doozy it was. I won’t reveal what company it was for or what the title of the challenges were, but I felt it would be beneficial for me to process the challenge by writing about it. Of course I cannot view the challenges now, therefore I am writing about this problem from memory and selecting my own testing parameters. This was also the second part of the technical challenge, slightly easier than the first challenge that was causing a great deal of stress (an array with a length of 6000+!)
The scenario was basically part of an escape room situation, because there would be no other reason to write this specific function. An array would be given, and a certain amount of points could be accumulated based on a few rules. The first rule, which wasn’t completely clear, was that the highest digit in the array would be the first points registered. Then any number one smaller than that digit would be eliminated from the array, no points added. Then the process would start over again, until there were no more items left in the array.
Again, the first part of the puzzle is to find the highest integer in the array. As has become natural for me, I created a for loop
to iterate through the array, comparing integers until the largest number was found. Then it would be added to a points variable, set at 0 before the loop condition begins. Finally it would be spliced from the array.
let element = 0
for (let i = 0; i < elements.length; i++) {
if (elements[i] > element) {
element = elements[i]
}
}
points+=element
let drop = elements.indexOf(element)
elements.splice(drop, 1)
The next step was to see if the array included elements that were one bigger or one smaller than the just deleted element. If there were, they would be eliminated through splicing, and the process would start over again.
let less = element - 1
let more = element + 1
if (elements.includes(less)) {
let small = elements.indexOf(less)
elements.splice(small, 1)
} else if (elements.includes(more)) {
let big = elements.indexOf(more)
elements.splice(big, 1)
}
}
This was all wrapped in a while
loop that would stop once the array was empty. Overall it's a basic code that passed multiple testing parameters, more than the first challenge. With this test, it wouldn't show which scenarios failed, and most of them seemed to be very large arrays. At first glance, it looks lengthy and I'm sure there is a cleaner and shorter solution but I'm proud that I completed it.
I am hopeful that these challenges are at least helping me get a true glimpse of what to expect during a technical interview. I am least coming up with solutions that manage to pass some testcases, and I am not completely overwhelmed when reading the problem. Any progress is better than no progress. Hopefully soon, it will all pay off.
Posted on June 9, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.