hashnode.com/post/can-anyone-give-me-a-comprehens… check the explanation of Todd.
And after that think about what substr needs to do. if a string is an array of characters and you can access every position but you have to select a range
so if k is the length of the range and n is the length of the string it would be O(k). The big O notation is a lot about perspective.