k | Returns k - th missing element . It returns - 1 if no k is more than number of missing elements . ; Insert all elements of givens sequence b [ ] . ; Traverse through increasing sequence and keep track of count of missing numbers . ; driver program to test the above function
function find ( a , b , k , n1 , n2 ) { var s = new Set ( ) ; for ( var i = 0 ; i < n2 ; i ++ ) s . add ( b [ i ] ) ; var missing = 0 ; for ( var i = 0 ; i < n1 ; i ++ ) { if ( ! s . has ( a [ i ] ) ) missing ++ ; if ( missing == k ) return a [ i ] ; } return - 1 ; } var a = [ 0 , 2 , 4 , 6 , 8 , 10 , 12 , 14 , 15 ] ; var b = [ 4 , 10 , 6 , 8 , 12 ] ; var n1 = a . length ; var n2 = b . length ; var k = 3 ; document . write ( find ( a , b , k , n1 , n2 ) ) ;