Pergunta de entrevista da empresa KLA

Given a value n. There will be array of size n and each array element represents the deadline to complete a project. The Project is divided into 3 groups and also given a value d, find the number of ways to complete the project such that the total time should be equal to the value d .Here one condition is that no two consecutive projects should be taken from the same group.