First question in codingame kirk's quest solved
2nd question in codingame's kirk's quest partially solved

we may need to use graph algorithms to solve this