Find the 20 longest strings in a text file.
Anonymous
Another way can be to just traverse the strings and keep a min b-tree to keep the minimum element on the top. When size of tree + 20, then only insert (replace) in tree, if the current string length > root of tree(min) . This will take O(log20) for each insertion and O(N) for traversal.
Check out your Company Bowl for anonymous work chats.