Sort Array by Reversing a Subarray
You are given an array of 'N' distinct integers, 'ARR'. Determine if it is possible to sort this array by selecting a continuous subarray and reversing it. Return 'true' if sorting is possible by this method, otherwise return 'false'.
Example:
Input:
ARR = [3, 2, 1]
Output:
true
Explanation:
The entire array can be reversed to get [1, 2, 3], which is sorted.
Input:
ARR = [1, 3, 2, 4]
Output:
true
Explanation:
Reversing the subarray [3, 2] results in the sorted array [1, 2, 3, 4].
Constraints:
- 1 <= T <= 10
- 1 <= N <= 10^6
- 1 <= ARR[i] <= 10^9
- Time Limit: 1 sec

AnswerBot
1y
The question asks whether it is possible to sort an array by choosing a continuous subarray and reversing it.
Check if the array is already sorted. If yes, return true.
Find the first and last elements ...read more
Help your peers!
Add answer anonymously...
Unthinkable Solutions Software Developer interview questions & answers
A Software Developer was asked 9mo agoQ. Given an array of intervals where intervals[i] = [starti, endi], merge all overl...read more
A Software Developer was asked 8mo agoQ. Implement debouncing, create a nodejs server with a get / post api, a puzzle, ja...read more
A Software Developer was asked 8mo agoQ. Designing dbms for a college website
Popular interview questions of Software Developer
A Software Developer was asked 9mo agoQ1. Given an array of intervals where intervals[i] = [starti, endi], merge all overl...read more
A Software Developer was asked 7mo agoQ2. Implement debouncing, create a nodejs server with a get / post api, a puzzle, ja...read more
A Software Developer was asked 7mo agoQ3. Designing dbms for a college website
>
Unthinkable Solutions Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

