Close
Topic list
Reverse The Array
EASY
15 mins
Arrays
Topics (Covered in this problem)
Problem solved
Skill meter
Arrays
-
-
Other topics
Problem solved
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

# Reverse The Array

Contributed by
Dhruv Sharma
Easy
0/40
Avg time to solve 15 mins
Success Rate 85 %
Share

## Problem Statement

#### Example:

``````We have an array ARR = {1, 2, 3, 4, 5, 6} and M = 3 , considering 0
based indexing so the subarray {5, 6} will be reversed and our
output array will be {1, 2, 3, 4, 6, 5}.
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1:
``````2
6 3
1 2 3 4 5 6
5 2
10 9 8 7 6
``````
##### Sample Output 1:
``````1 2 3 4 6 5
10 9 8 6 7
``````
##### Explanation 1:
``````For the first test case,
Considering 0-based indexing we have M = 3 so the
subarray[M+1 … N-1] has to be reversed.
Therefore the required output will be {1, 2, 3, 4, 6, 5}.

For the second test case,
Considering 0-based indexing we have M = 2 so the
subarray[M+1 … N-1] has to be reversed.
Therefore the required output will be {10, 9, 8, 6, 7}.
``````
##### Sample Input 2:
``````2
7 3
1 4 5 6 6 7 7
9 3
10 4 5 2 3 6 1 3 6
``````
##### Sample Output 2:
`````` 1 4 5 6 7 7 6
10 4 5 2 6 3 1 6 3
``````
Auto
Console