Education + Jobs Hiring Website - 2025
0 like 0 dislike
31 views
first one is find the rightmost element index where j>i and arr[j]<arr[i]

 

example arr[]=[8, 2, 5, 3]

op[3, 0, 1, 0]

 

second one you have given the digits find the smallest string that can be formed by adding two numbers x or y example 27 is given x 2 and y 3 form smallest string such that 27 is subsequence of formed string let we start with curr=0 now add 2 or 3 check last digit if we find the last digit in 27 from the starting mean we have find the string but we have to find the smallest string ans for 27 is 247 that smallest another string can also be formed that is 257

 

curr+2

curr+3 no match with first char of 27 discard it

 

(curr+2)+2>>curr24

(curr+2)+3>>curr25

 

choose smallest curr24+2 or 3 then curr246 and curr247 now we find the match with 27 this is my smallest string return if we didnt find this return -1;
ago in Online Assessments by Expert (137,560 points) | 31 views

Please log in or register to answer this question.