You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is an optimized version of your program.
Key improvements.
- The `for` loop for `k` is replaced with a formula for arithmetic series sum, eliminating iteration.
- The sum for `j` is done via the same formula (since sum(range(number)) is (number-1)*number//2).
- Used a list comprehension for `str(i)` and `join`, which is slightly faster than the generator form in this context.
This version will run much faster, especially for large `number` values. All logic and return values are preserved.
0 commit comments