Kapil Patel
1 min readJul 7, 2021

Write a program to reverse an array

Solution passes the test case but may not be most efficient

I will keep updating this with better solution.

Solution using C#.

using System;
public class Codemirror{

static void ReverseArray (int[] inputArr)
{
int arrayHalfLength = inputArr.Length/2;
for(int i = 0; i < arrayHalfLength ; i++)
{
int temp1 = inputArr[i];
int temp2 = inputArr[inputArr.Length-1-i];
//swap
inputArr[i] = temp2;
inputArr[inputArr.Length-1-i] = temp1;
}
PrintArray(inputArr);

}

static void PrintArray (int[] inputArr)
{
for(int i = 0; i < inputArr.Length; i++)
{
Console.Write(inputArr[i] + ", " );
}
Console.WriteLine();
}

static public void Main (){
//Code

//int[] arr = {11, 12, 5, 9, 16, 56, 8};
int[] arr = {5, 8, 2, 1};
PrintArray(arr);
ReverseArray(arr);
}
}

This post is another part of DSA RoadMap by The Code Skool

Youtube video:

https://www.youtube.com/watch?v=WjYdkHzcGhc&list=PL6ZXPAW2GSTuO4m6wCITtyVobnD1O1dkj

GeeksForGeeks top 50 array coding problems

https://www.geeksforgeeks.org/top-50-array-coding-problems-for-interviews/

Kapil Patel
Kapil Patel

Written by Kapil Patel

Software engineer | loves working in a startup like environment

No responses yet