Collect the parts, then join.
transcript
Four codes. One report. Do not copy the text. Collect the parts. Then build once. A builder grows at its end. It never copies old text.
The builder starts empty. D four is written at the end. A bar goes in. Then C thirty. Nothing old is copied. Each piece is written once. The old text stays put. The builder grows like a tape. Room doubles when it is full.
B seven and A twelve follow. Each character was written once. One last step makes the string. That is the only full copy. The builder holds all the text. Space grows with the text.
The bar goes before a piece. Not before the first piece. Then no bar is left at the end. Python: a list and join. Java: a StringBuilder. C plus plus: a string with plus equals. JavaScript: an array and join.
Collect, then build once. Full breakdown in the lecture.