You are viewing a single comment's thread. Return to all comments →
This is my approach to solve this challenge!
int find_nth_term(int n, int a, int b, int c) { int ans = 0, ansa, ansb, ansc; if(n == 1) ans = a; if(n == 2) ans = b; if(n == 3) ans = c; if(n == 4) ans = c + b + a; if(n > 4) { ansc = find_nth_term(n - 3, a , b , c); ansb = find_nth_term(n - 2, a , b , c); ansa = find_nth_term(n - 1, a , b , c); ans += ansa + ansb + ansc; } return ans; }
Seems like cookies are disabled on this browser, please enable them to open this website
Calculate the Nth term
You are viewing a single comment's thread. Return to all comments →
This is my approach to solve this challenge!