Position in 2D Array - Serpentile Orderlocked Problem Submissions Leaderboard Discussions An n×n two-dimensional array with elements already arranged in a non-decreasing serpentile order. The arrangement for a 4×4 two-dimensional array is shown in Fig. 1. The element present at index [0][0] is the minimum and that at index [n-1][n-1] is the maximum. If one traverses this array starting from [0][0] and follows the marked arrow directions then the result will be a non-decreasing sorted sequence of elements. In this sequence, the pth largest element gets positioned at p. Taking this p as an input from the user, write an efficient algorithm to print the row and column indices along with the value of the pth largest element in the sorted sequence.
Click Fig. 1 to view the image. In case link does not work one can refer the figure shown below.
1 2 6 7 3 5 8 13 4 9 12 14 10 11 15 16 Input Format
Line 1 contains an integer N, representing the dimension of an N × N array. Line 2 contains N×N space separated array elements in row major order. Line 3 contains an integer P, position of the pth largest element in non-decreasing sorted sequence. Constraints
All inputs range in between 1 and 1000. Output Format
Line 1 displays three space separated integers, row index of the pth element, column index of the pth element, and the value of the pth element. Sample Input 0
4 124 169 505 563 224 278 585 803 251 638 690 934 664 684 944 981 9 Sample Output 0
2 1 638 Sample Input 1
5 1 2 6 7 15 3 5 8 14 16 4 9 13 17 22 10 12 18 21 23 11 19 20 24 25 23 Sample Output 1
3 4 23