Goldman Sachs Interview Question

design an algorithm to detect deadlocks