Sort by

recency

|

50 Discussions

|

  • + 0 comments
    ** Does anyone know why below code give wrong answer on some test cases**

    public static long sumOfGroup(int k) {

     long ele=(k*(k-1))+1;
    long sum=(k*(2*ele+(k-1)*2))/2;
    return sum;
    
    
    
    }
    
  • + 0 comments
    def sumOfGroup(k):
            return k**3
    
  • + 1 comment

    seriuosly, Why does "k*k*K" solution work !?

    I mean what the math explaination behind this?

  • + 0 comments
    
    
    // Return the sum of the elements of the k'th group.
    long long int x=(k*(k-1)+1);
    long long int sum=x;
    for(int i=0;i<k-1;i++){
        x=x+2;
        sum+=x;
    }
    

    return sum; }https://)

  • + 0 comments

    For th group, how many number were used in previous groups?

    So, the first number in th group will be th odd number.

    th odd number is given as . So, the first number in th group will be

    Now, the group is an AP with first term given above and common difference (odd numbers).

    In C++, return 1L * k * k * k.