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.
From "smart" rank and up we will encounter problems which we actually have to fully analyze and solve, not just fixing a few bugs.
The code above starts with creating an array of numbers, then it declares two variables R=0
and T=2
. Further, we have a for-loop with a conditional R++
operation, this executes only if el
is equal to T
. Due to the simplicity of the code, we can summarize the algorithm as such: the code is counting (using R
) the number of occurrences of number T
in the array.
Since T=2
, we see that 2 appears only once in the array, so R
should be 1:
If you feel inspired and motivated to upgrade your coding + debugging skills, join me on the Road to Genius at https://nevolin.be/codr/
Top comments (0)