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.
Pro Tip for Java user: Use the StringBuilder class.
String is immutable, so everytime you add to a string, it creates a new object! With an input of 100000, you'd have created 30000 new objects each containing the string it was before it plus what you added to it! You can imagine how innefficient this is.
StringBuilder, 1 object, 1 problem solved. Use StringBuilder today!
(This message is brought to you by StringBuilder Co. We build Strings in a timely manner for you, so you don't have to!)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and The Beast
You are viewing a single comment's thread. Return to all comments →
Pro Tip for Java user: Use the StringBuilder class.
String is immutable, so everytime you add to a string, it creates a new object! With an input of 100000, you'd have created 30000 new objects each containing the string it was before it plus what you added to it! You can imagine how innefficient this is.
StringBuilder, 1 object, 1 problem solved. Use StringBuilder today!
(This message is brought to you by StringBuilder Co. We build Strings in a timely manner for you, so you don't have to!)