Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
if your integer range is limited (it seems it could be so as they only id a vertex) you could use a BitSet instead of a HashSet...this should be way faster as it spares the hash calculations and memory bandwidth
@Billal the OP was asking: "What ways can I improve?"...in my humble opinion, this is the BEST way to improve, and excuse me if this sounds harsh: the main reason he didn't progress to the next step in the application process...Hashtables are a basic concept, and if you do programming, you must know them