Two Pointer Algorithm Javascript Substring Function In Python