StringBuilder III
 
Another example where string concatenation leads to TLE while the StringBuilder approach gets to the expected solution. A lot of concatenations using Strings in C# will lead to many objects being created all the time, which not only wastes memory but also time in the process (including GC). This article from SO discusses this theme well:  c# - benefits of using a stringbuilder - Stack Overflow Code is down below, cheers, ACC String Compression III - LeetCode 3163. String Compression III Medium 45 3 Add to List Share Given a string  word , compress it using the following algorithm: Begin with an empty string  comp . While  word  is  not  empty, use the following operation: Remove a maximum length prefix of  word  made of a  single character   c  repeating  at most  9 times. Append the length of the prefix followed by  c  to  comp . Return the string  comp .   Example 1: Input:   word ...