Strange-advertising — HackerRank Problem

Day Shared Liked Cumulative
1 5 2 2
2 6 3 5
3 9 4 9
4 12 6 15
5 18 9 24
class Result
{
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;
}
return sum;
}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store