Mr.Avathar and his Algorithm

0

0 votes
Medium
Problem

Mr.Avathar is trying to design a new sorting algorithm for sorting large data sets in ASCENDING ORDER.But the problem with his algorithm is that there remains a subset in the complete set which is unsorted.This particular subset makes the whole set unsorted.Your task is to help Mr.Avathar in finding out the start and end of this unsorted subset so that Mr.Avathar can improve his algorithm

INPUT FORMAT

N represents number of input values
Next Line contains
N space seperated input values
ai represents input value

CONSTRAINTS

1≤N≤100000
1≤ ai ≤100000

OUTPUT

If the set is already in ascending order print SET ALREADY IN ASCENDING ORDER
start index of unsorted set followed by last index of unsorted set
start index and last index are space seperated
.

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

Consider the set [1,4,7,5,10,18,17,26,30,45,50,62]. In the complete set,the subset [7,5,10,18,17] is unsorted. So the length of the unsorted subset is 5

Consider the set [1,2,3,4,5]. As this set is already in ascending order,we have to do nothing.The length of the unsorted subset is zero.

Editor Image

?