Milly and her classmates
Practice
3.7 (354 votes)
Ready
Map
Approved
Easy
Problem
45% Success 2933 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Milly and her classmates are standing in a queue to attend the morning assembly of her school. According to the rule any student should stand in his/her proper place in order to make the queue completely visible till the end. Milly being the class monitor is required to make this queue such that students should be standing in an increasing order of their heights. Student with smaller height should stand at front and the student with higher height should stand at the end. She can reverse one particular group of the students. But she can perform this action only once. Here group of students means one particular continuous segment. Height of the students are distinct. Your task is to help her in solving this problem. You have to output starting and ending position of that group. In case, if queue is already in required condition or it is not possible to solve then consider starting and ending positions as -1.

Input

  • First line of the input will contain T (No. of test cases).
  • For each test case, first line will contain a integer N (No. of students). Second line will contain N space separated integers (denoting distinct height of students in initial queue)

Output

  • For every test case, print the two space separated integers denoting the starting and ending positions of group in a new line.

Constraints

  • 1 ≤ T ≤ 10
  • 1 ≤ N ≤ 104
  • 1 ≤ Height ≤ 109

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
Tags:
Sparse TableHardTreeLife-cycle assessmentLoopsSegment tree
Points:30
500 votes
Tags:
MathematicsSieveEasy-MediumBinary search algorithmMathematicsMathamatics
Points:20
153 votes
Tags:
AlgorithmsApprovedBreadth First SearchEasyGraphsGreedy AlgorithmsMathOpen