Medium csharp

Reverse array #53

Problem

Reverse [2, 4, 6, 8, 10, 12, 14] in-place.

Hints
  • Swap ends

Your practice code

Ready — edit the code above and click Run.

Solution

using System;

class Program
{
    static void Main()
    {
        int[] arr = { 2, 4, 6, 8, 10, 12, 14 };
        int l = 0, r = arr.Length - 1;
        while (l < r) { (arr[l], arr[r]) = (arr[r], arr[l]); l++; r--; }
        Console.WriteLine(string.Join(", ", arr));
    }
}

Try solving on your own first, then reveal the official answer.

Explanation

Two-pointer reverse.

Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details