function findStaircaseSegment(n, k, heights) {
for (let i = 0; i < n; i++) {
// Try all segments with lengths from 2 to k, starting at index i
for (let length = 2; length <= k && i + length <= n; length++) {
// Extract the segment and sort it
const segment = heights.slice(i, i + length);
const sortedSegment = [...segment].sort((a, b) => a - b);
// Check if sorted segment is non-decreasing
let isNonDecreasing = true;
for (let j = 1; j < sortedSegment.length; j++) {
if (sortedSegment[j] < sortedSegment[j - 1]) {
isNonDecreasing = false;
break;
}
}
if (isNonDecreasing) {
// Output the result as a 1-based index range
return `YES\n${i + 1} ${i + length}`;
}
}
}
// If no such segment was found, return "NO"
return "NO";
}
// Sample input
const n = 5;
const k = 2;
const heights = [1, 2, 4, 3, 5];
console.log(findStaircaseSegment(n, k, heights));