Jane Street Interview Question

variant of connect - 4