I tried solving the leetcodeLeetCode question like many others, trying to incorporate the O(n) time complexity requirement.
by manually calculating the time cost (and also the aiAI tool by LeetCode) I. I seem to get O(n) time complexity, but this code is incredibly slow. Is it due to the 'chunkiness' of it or something else.? Feel free to point out any redundancies or inefficient lines.