1def build_report(rows):
2 report = ""
3 for row in rows:
4 report += format_row(row) + "\n"
5 return report
6
7# With 100,000 rows: copies ~5 billion characters total
8# Expected: O(n), Actual: O(n²)
no lines flagged
#042PracticeMedium15 min · 120 XP
String Concatenation in Loop is O(n²)
Building a large report string by concatenation in a loop is 100x slower than expected. Find the performance fault.
Flagged linesNo lines flagged yet
What's wrong?
Flag a line or write a note to submit.