Each day I solve several coding challenges and puzzles from Codr's ranked mode. The goal is to reach genius rank, along the way I explain how I solve them. You do not need any programming background to get started, and you will learn a ton of new and interesting things as you go.
In this challenge we need to fix three bugs 🐼, 💧 and 💰. The first one 🐼 appears on the first line, it must be a numeric value of the array arr
. We can't figure out its value without analyzing the code first, so let's proceed.
We notice that the code has a while-loop that iterates as long as the array is not empty (and uses pop to extract values). The if-condition reveals that variable R
is used to keep track of the largest value, as a result 💧 is most likely R
. Upon closer inspection, variable prev
serves no purpose, it's pretty much dead code. Bug 💰 has to be =
, because the line prev = x
tracks the "previous" value.
With all of this information we can easily find 🐼: the challenge code is all about finding the largest value in the array. And the challenge states that R = 9
, since 9 is already in the array, 🐼 can be any numeric value (including 9).
Join me on the Road to Genius and upgrade your programming skills, at https://nevolin.be/codr/
Top comments (0)