Two Pointer Algorithm Javascript Substring Function In Mysql