educative.io

Unclear how to provide an output for the coding challenge

Hi, I’m trying to solve the challenge but it’s a little bit unclear how I should provide the result of the algorithm, since the function has void as a return type. Whatever I assign to arr variable does nothing, the tests always fail because the output of my program matches the input, even when I overwrite the arr variable with an empty array. (please notice that I haven’t seen the solution section yet since I want to solve it myself).


Course: https://www.educative.io/courses/data-structures-interviews-cs
Lesson: Challenge 8: Right Rotate an Array by One - Data Structures for Coding Interviews in C#

Hi @Alex3 !!
It seems like you’re on the right track with your implementation. Since the function rotateArray has a void return type, you don’t need to return anything explicitly. Instead, you should directly modify the input array arr within the function to achieve the desired rotation.
Here’s a step-by-step approach you can follow:

  1. Store the last element of the array in a temporary variable.
  2. Shift all elements of the array to the right by one position.
  3. Assign the value of the temporary variable to the first element of the array.
    This implementation should rotate the array to the right by one position, satisfying the requirements of the problem statement. If you encounter any issues or have further questions, feel free to ask! Happy Learning :blush:
1 Like