Optiver Interview Question

A harder leetcode style problem about graphs