It’s not 100% the same, but understanding it should enable you to use the same idea for this problem.