DEV Community

Discussion on: Re-Learning fundamentals

Collapse
nineismine profile image
nineismine • Edited

Let's take one of these easy problems apart.

HackerRank says:

A left rotation operation on an array shifts each of the array's elements 1 unit to the left. For example, if 2 left rotations are performed on array , then the array 1,2,3,4,5 would become 3,4,5,1,2 .

Given an array a of n integers and a number, d, perform d left rotations on the array. Return the updated array to be printed as a single line of space-separated integers.


In the real world I would say (if describing this problem to a developer)


OK we have a system that is going to return a series of numbers
1,2,3,4,5.

We have this other process that is going to do Something and that is going to result in all of the numbers shifting to the left ,each time it that process occurs.

So if Something happens 2 times then our collection will look like this :
3,4,5,1,2

You see, each of the elements stay in our collection but are moving left, starting over at the end of the array if they are moved past the beginning.

The second part of this problem is to me just incomprehensible.. I have to read it over 4 or 5 times because they are using such poorly named variables.


**
Given an array a of n integers and a number, d perform d left rotations on the array. Return the updated array to be printed as a single line of space-separated integers.**


So the numbers we have to work on will be stored in an int array, and we don't always know how many *elements * there will be in our array.

We will need to write some code that can accept an **int **that tells us how many rotations to perform on the array.

Our function will then shift the values in the array one time to the left for each rotation. (Numbers that reach the first position of the array will be moved to the end of the array)


To me my definition is just so much more easy to understand. Is that the point? Are they giving us a code test or are they testing if we can do the mental back flips that are required to read their poor descriptions?