How to iterate from the end to the start in a string? (In constant space and linear time complexity)
There is an index called endIndex in a string which is the index after a last element of a string. So, I can iterate through a string from start like this:
Swift
var index = s.startIndex
while index != s.endIndex {
index = s.index(after: index)
}
But I want to iterate from the end. Is there an elegant way to do it? Thanks in advance!