Strange-advertising — HackerRank Problem
HackerLand Enterprise is adopting a new viral advertising strategy. When they launch a new product, they advertise it to exactly people on social media.
On the first day, half of those people like the advertisement and each shares it with of their 3 friends. At the beginning of the second day, people receive the 2*3 =6 advertisement.
Each day, of the recipients like the advertisement and will share it with friends on the following day. Assuming nobody receives the advertisement twice, determine how many people have liked the ad by the end of a given day, beginning with launch day as day .
Day Shared Liked Cumulative
1 5 2 2
2 6 3 5
3 9 4 9
4 12 6 15
5 18 9 24
The progression is shown above. The cumulative number of likes on the day is 24.
public static int viralAdvertising(int n)
int sum = 2;
int liked = 2;
int shared =5; for(int i=2 ; i <=n ;i++)
shared = liked*3;
sum = sum + shared/2;
liked = shared/2;