min window substr reimpl