Given a number N, the task is to find the Nth term of this series:
-1, 2, 11, 26, 47, 74, .....
Input: 3 Output: 11 Explanation: when N = 3 Nth term = ( (3 * N * N) - (6 * N) + 2 ) = ( (3 * 3 * 3) - (6 * 3) + 2 ) = 11 Input: 9 Output: 191
The Nth term of the given series can be generalised as:
Nth term of the series : ( (3 * N * N) - (6 * N) + 2 )
Below is the implementation of the above problem:
Time Complexity: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
In case you wish to attend live classes with industry experts, please refer Geeks Classes Live