ByteDance Interview Question

How to iterate the substring