text: k | Function to find the sum of minimum of all subarrays ; Insert all the elements in a set ; Find the maximum and minimum element ; Traverse from the minimum to maximum element ; Check if " i " is missing ; Check if it is kth missing ; If no kth element is missing ; Driver code
code: < ? php function findKth ( $ arr , $ n , $ k ) { $ missing = array ( ) ; $ count = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) array_push ( $ missing , $ arr [ $ i ] ) ; $ missing = array_unique ( $ missing ) ; $ maxm = max ( $ arr ) ; $ minm = min ( $ arr ) ; for ( $ i = $ minm + 1 ; $ i < $ maxm ; $ i ++ ) { if ( ! in_array ( $ i , $ missing , false ) ) $ count += 1 ; if ( $ count == $ k ) return $ i ; } return -1 ; } $ arr = array ( 2 , 10 , 9 , 4 ) ; $ n = sizeof ( $ arr ) ; $ k = 5 ; echo findKth ( $ arr , $ n , $ k ) ; ? >