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’s an optimized version of your code for Python 3.11.6. The main points of improvement are.
- Replace `" ".join(str(i) for i in range(number))` with a faster approach that avoids repeated calls to `str(i)`. Using `map(str, ...)` is significantly faster and uses less overhead.
- Since `j` is not used, you can remove its assignment to avoid unnecessary computation.
- You don't need `min` every time if your `_cached_joined` function is correct, but preserving it as per the original function logic for correctness on inputs >1000.
- The lru_cache remains, as it's critical to performance for repeated calls.
Here’s the optimized version.
This program will run strictly faster, especially for large input values and repeated calls due to the combination of a faster string conversion and the efficient use of the cache.
0 commit comments