Number of ways to display ad for a number of slots and seperator
Anonymous User
280

Given n number of slots to display an ad find all the ways to schedule an ad such that we leave seperator number of slots between the two ad displayed slots.

For e.g. we have 3 slots and seperator is 1 then we can schedule the ad in 5 ways

1. - - -
2. x - -
3. - x -
4. - - x
5. x - x

if we have 3 slots and seperator is 0 then we can schedule the ad in 8 ways

1. - - -
2. x - -
3. - x -
4. - - x
5. x - x
6. x x x
7. x x -
8. - x x

We need to implement a function which returns number of ways we can schedule the ad.

public int numberOfWays(int slots, int seperator) {
	
}

I tried to solve it using recursion but could not get the right answer. If you can point me to what catogory this problem belongs too like permutation or Dynamic programming that would be helpful.

Comments (2)