Given an array A = x1x2 … xn, the smallest nearest value corresponding to xi is defined as Vi =…

Given an array A = x1x2 … xn, the smallest nearest value corresponding to xi is defined as Vi = minj>i{ j|xj < xi}.="" it="" is="" undefined="" if="" all="" elements="" to="" the="" right="" of="" xi="" are="" larger="" than=""> . The all smallest nearest value problem (ANSV) is to compute for all i for a given array A. For example, for the array [5,3,7,1,8], V1 = 2,V2 = 4,V3 = 4,V4 = U,V5 = U. Here U means undefined. Design a linear time algorithm for the ANSV problem.