Print all strings of maximum length from an array of strings | Python3 program to implement the above approach ; 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 lenn ; 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
import sys NEW_LINE def maxLength ( arr ) : NEW_LINE INDENT lenn = - sys . maxsize - 1 NEW_LINE N = len ( arr ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT l = len ( arr [ i ] ) NEW_LINE if ( lenn < l ) : NEW_LINE INDENT lenn = l NEW_LINE DEDENT DEDENT return lenn NEW_LINE DEDENT def maxStrings ( arr , lenn ) : NEW_LINE INDENT N = len ( arr ) NEW_LINE ans = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( lenn == len ( arr [ i ] ) ) : NEW_LINE INDENT ans . append ( arr [ i ] ) NEW_LINE DEDENT DEDENT for i in range ( len ( ans ) ) : NEW_LINE INDENT print ( ans [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT def printStrings ( arr ) : NEW_LINE INDENT max = maxLength ( arr ) NEW_LINE maxStrings ( arr , max ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ " aba " , " aa " , " ad " , " vcd " , " aba " ] NEW_LINE printStrings ( arr ) NEW_LINE DEDENT