It will return correct values as it will iterate until the length is met (and therefore i is not less than s.length() but is equal to s.length). It is poorly designed as s.length() can be used directly to obtain the number of characters in a string. This function likely has a Big O notation greater than O(n) because - due to the unnecessary loop - it has to iterate again. It also increments size multiple times instead of mutating it once when the for loop is finished to reduce on read/write time