ByteDance interview question

How to iterate the substring