Sort the Array

Practice this coding question on Coding Gurukul.

Problem statement

A packing line has trays with distinct numeric labels. A handling robot can lift one consecutive section and put that section back in reverse order. Before authorizing the lift, the operator needs to know whether that single action can arrange the entire line in increasing order. Your task Decide whether reversing exactly one contiguous segment sorts the array in strictly increasing order. If it does, report the segment using one-based endpoints. All positions outside the chosen segment stay fixed. Important details A segment may contain just one element, which leaves the array unchanged. If the array is already sorted, print the segment 1 1. For an unsorted array of distinct values, any successful nontrivial reversal has uniquely determined endpoints. Sorting by swaps, moving a segment elsewhere, or doing two reversals is not allowed. Worked example For labels 2 8 6 4 10, reversing positions 2 through 4 gives 2 4 6 8 10, so print yes followed by 2 4. For 3 1 2, reversing any single segment still leaves an inversion, so print no. A one-tray line is already sorted and uses 1 1.

Input format

First line: n. Second line: n distinct integers.

Output format

Print no if impossible. Otherwise print yes on the first line and l r on the second line. Use 1 1 when already sorted.

Constraints

1 <= n <= 1000; 1 <= label[i] <= 1000000000; all labels are distinct.

Sample input

5
2 8 6 4 10

Sample output

yes
2 4

Sign in to run or submit a solution in C++, Java or Python.

Loading Coding Gurukul…