Extract stream prefix before stop token | Microsoft Interview Question