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.
Today we start with two relatively easy challenges. We have seen similar versions of these challenges before, but this time there are no bugs to be fixed.
This challenge starts with an empty array, followed by a for-loop that pushes numbers into the array. The challenge is to determine the value of R
which is arr[N-4]
. Let's briefly analyze the for-loop: it's adding numbers into arr
starting from 0 to N=7
(excluded). So arr
will eventually contain the following: 0,1,2,3,4,5,6
.
Now R
is the value at (N-4)th index, that is the 3rd index, which is 3.
The second challenge starts off with an array of random numbers. The for-loop iterates over each number in this array, then the if-condition checks if the element is greater than R
, if so R
takes its value. In a nutshell this code keeps track of the largest number from the array. To solve it, simply find the largest number in arr
which is 9.
By solving these challenges you train yourself to be a better programmer. You'll learn newer and better ways of analyzing, debugging and improving code. As a result you'll be more productive and valuable in business. Join me on the Road to Genius and upgrade your programming skills, at https://nevolin.be/codr/
Top comments (0)