title: Maximize sum of list with no more than k consecutive elements from input
body: <p>I have an array of <strong>N</strong> numbers and I want remove only those elements from the list which when removed will create a new list where there are no more <strong>K</strong> numbers adjacent to each other. There can be multiple lists that  can be created with this restriction. So I just want that list in which the sum of the remaining numbers is maximum and as an output print that sum only.</p>
  
  <p>The algorithm that I have come up with so far has a time complexity of O(n^2). Is it possible to get better algorithm for this problem?</p>
  
  <p><a href="https://www.hackerrank.com/challenges/billboards" rel="nofollow">Link to the question</a>.</p>
  
  <p>Here's my attempt:</p>
  
  <pre><code>int main()
  {
      //Total Number of elements in the list
      int count = 6;
      //Maximum number of elements that can be together
      int maxTogether = 1;
  
      //The list of numbers
      int billboards[] = {4, 7, 2, 0, 8, 9};
  
      int maxSum = 0;
      for(int k = 0; k&lt;=maxTogether ; k++){
          int sum=0;
          int size= k;
  
          for (int i = 0; i&lt; count; i++) {
              if(size != maxTogether){
                  sum += billboards[i];
                  size++;
              }else{
                  size = 0;
              }
          }
          printf("%i\n", sum);
          if(sum &gt; maxSum)
          {
              maxSum = sum;
          }
      }
      return 0;
  }
  </code></pre>