Medium csharp

Reverse array #48

Problem

Reverse [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36] 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 = { 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36 };
        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