Find n-th term of series 1, 3, 6, 10, 15, 21 | Practice | GeeksforGeeks

Given a number N, find the Nth term in the series 1, 3, 6, 10, 15, 21...
 
Example 1:
Input :
N = 4 
Output:
10
Explanation:
The 4th term of the Series is 10.
Example 2:
Input :
N = 3 
Output:
6
Explanation:
The 3rd term of the Series is 6.
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function findNthTerm() which takes an Integer N as input and returns the answer.
 
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= N <= 104
0
bhaskarkurukuri12 weeks ago
The simple and simplified solution in C++:
 
int findNthTerm(int N) {       return (N*N+N)/2;   }
0
shobhitgautam19992 weeks ago
class Solution {   static int findNthTerm(int N) {              if(N == 1)       {           return 1;       }              int counter=2;       int sum = 1;              while(N !=1)        {           N--;             sum = sum+counter;            counter = counter + 1;        }              return sum;   }};
0
rumi1w8ry3 weeks ago
def findNthTerm(self, N):
       # code here 
       return (N*N+N)//2
+1
rb0012 months ago
 // Code By Rahul Bisht
public:   int findNthTerm(int N) {       // code here      return (N*(N+1))/2;   }};
0
samirmistry12 months ago
class Solution {
    static int findNthTerm(int N) {
        // code here
        int[] arr = new int[N];
        arr[0] =1;
        for(int i=1;i<N;i++)
        {
            arr[i] = (i+1) + arr[i-1];
            /*
            arr[1] = 1
            2 = 2+arr[1]
            3 = 3 + arr[3]
            4 = 4 + arr[4]
            */
        }

        return (arr[N-1]);
        
    }
};
0
mayank180919992 months ago
   int findNthTerm(int N) {
        // code here
        return (N*N+N)/2;
    }
-1
rsbly7300953 months ago
class Solution {
   findNthTerm(N){
      return (N*((N+1)/2))
   }
}
0
ishangarg23 months ago
recursive solution:
   int sum = 0;       if(N == 0) return 0;       sum = findNthTerm(N-1);       return sum + N; 
+1
sayanmazumder9993 months ago
JAVA
      int sum = 1;        for(int i = 2; i<N+1; i++) sum += i;            return sum;
0
kirankolte21563 months ago
 
class Solution {   static int findNthTerm(int N) {       // code here       return N*(N+1)/2;                     }}
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested 
                                    against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code.
                                    On submission, your code is tested against multiple test cases consisting of all
                                        possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as
                                        the final solution code.
You can view the solutions submitted by other users from the submission tab.
Make sure you are not using ad-blockers.
Disable browser extensions.
We recommend using latest version of your browser for best experience.
Avoid using static/global variables in coding problems as your code is tested 
                                against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases in coding problems does not guarantee the 
                                correctness of code. On submission, your code is tested against multiple test cases
                                    consisting of all possible corner cases and stress constraints.