We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Very elegant solution, one small note just to catch an edge case, if the user enters 0 for the first input, you will still be trying to initalize your first set by calling scan.next() but that will throw an error if they don't enter any strings. I would do a check:
if (t>0) {.........} to account for this special case. But other than that, beautiful solution.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Gemstones
You are viewing a single comment's thread. Return to all comments →
Very elegant solution, one small note just to catch an edge case, if the user enters 0 for the first input, you will still be trying to initalize your first set by calling scan.next() but that will throw an error if they don't enter any strings. I would do a check: if (t>0) {.........} to account for this special case. But other than that, beautiful solution.