Check if a pair of strings exists that starts with and without the character K or not | Function to check whether a pair of strings exists satisfying the conditions ; Stores the visited strings ; Iterate over the array arr [ ] ; If first character of current string is K ; Otherwise ; Adding to the visited ; Given Input
function checkhappy ( arr , K , N ) { let visited = new Set ( ) ; for ( let s of arr ) { if ( s [ 0 ] == K ) { if ( visited . has ( s . slice ( 1 ) ) ) return " " ; } else { if ( visited . has ( K + s ) ) return " " ; } visited . add ( s ) ; } return " " ; } let arr = [ " " , " " , " " , " " , " " , " " ] ; let K = " " ; let N = arr . length ; document . write ( checkhappy ( arr , K , N ) ) ;