Print all strings of maximum length from an array of strings | Function to find the length of the longest String from the given array of Strings ; Traverse the array ; Stores the length of current String ; Update maximum length ; Return the maximum length ; Function to print the longest Strings from the array ; Find the Strings having length equals to len ; Print the resultant vector of Strings ; Function to print all the longest Strings from the array ; Find the length of longest String ; Find and print all the Strings having length equals to max ; Driver Code
function maxLength ( arr ) { let len = Number . MIN_VALUE ; let N = arr . length ; for ( let i = 0 ; i < N ; i ++ ) { let l = arr [ i ] . length ; if ( len < l ) { len = l ; } } return len ; } function maxStrings ( arr , len ) { let N = arr . length ; let ans = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { if ( len == arr [ i ] . length ) { ans . push ( arr [ i ] ) ; } } for ( let i = 0 ; i < ans . length ; i ++ ) { document . write ( ans [ i ] + " " ) ; } } function printStrings ( arr ) { let max = maxLength ( arr ) ; maxStrings ( arr , max ) ; } let arr = [ " " , " " , " " , " " , " " ] ; printStrings ( arr ) ;