So regardless of how many operations you perform in your loop, you still touch N elements.
Chandra shekar M wrote:Hi,
In java String is stored as a char array; in java size of the array is predetermined and stored in head so getting the size of the array or string will be O(1).
and however string reverse will be O(N) it cant be less than this; as you will end up visiting each element when reversing.
Thanks
Chandra