Implement sampling and subarray algorithms | Google Interview Question