Slow IO on large input - a hint

Hi there!

A small hint for everyone who would like to solve any of the puzzles with large input.
I found myself struggling with time outs for Scrabble puzzle for large dictionaries. I figured out that reading words one by one (as template suggests) and adding them to a collection is so slow that it times out before the algorithm gets launched at all.

What I did instead is the following call:

Source.stdin.getLines().buffered

which returns a fast performing buffered iterator.
Hopefully it will help someone and it won’t be regarded as a spoiler as it’s a boilerplate code needed before the algorithm kicks in.

3 Likes

Tricks to help other like this one are always welcome. :wink: