title: What will be the optimal solution?
body: <p>Given <code>n&gt;=0</code>, create an array with the pattern <code>{1,1, 2,1, 2, 3, ... 1, 2, 3 .. n}</code>.</p>
  
  <p>As an example if you given <code>n=3</code>, your method should return array as <code>{1,1,2,1,2,3}</code>.</p>
  
  <p>My solution is here....</p>
  
  <pre><code>public int[] upSeries(int n) {
  
      int var1 = n + 1;        
      int var2 = n;
      int var3 = (var1*var2) / 2;
      int arr_length = var3;
      int value = 1;
      int index = 0;
      int[] arr = new int[arr_length];
      for (int j = 0; j &lt; arr.length; j++) {
          for (int p = 0; p &lt; j + 1; p++) {
              arr[index] = value;
              value++;
  
              if (index == arr.length - 1) {
                  arr[index] = n;
                  break;
              } else {
                  index++;
              }
          }
          value = 1;
      }
      return arr;
  }
  </code></pre>
  
  <p>What will be the best solution?</p>