[JavaScript] O(N) 59ms solution with comments
At most, 2 passes of arr are required.\n\n> With commentary:\n\njs\nvar kConcatenationMaxSum = function(arr, k) {\n  var MOD = 1000000007;\n  var totalSum = 0;\
At most, 2 passes of `arr` are required.\n\n> **With commentary:**\n\n```js\nvar kConcatenationMaxSum = function(arr, k) {\n  var MOD = 1000000007;\n  var totalSum = 0;\n  var localMax = 0;\n  var globalMax = 0;\n  \n  /**\n   * First loop: do Kadane\'s algorithm for max subarray sum\n   * with addition of calculating total sum for next steps.\n   * \n   * For Kadane\'s, @see: leetcode.com/problems/maximum-subarray/\n   */\n  arr.forEach((num) => {\n    totalSum += num;\n    localMax = Math.max(num, localMax + num);\n    globalMax = Math.max(localMax, globalMax); \n  });\n  \n  /**\n   * If k is 1, we don\'t need to check for second concat.\n   * Or if globalMax is still 0, all numbers were negative,\n   * so max sum will be subarray of length 0 = 0.\n   */\n  if (k === 1 || globalMax === 0) {\n    return globalMax % MOD;\n  }\n  \n  /**\n   * Calculate max sum of concatenating twice for case [1, -2, 1]\n   * where max sum is formed from end of first with beginning of second.\n   */\n  arr.forEach((num) => {\n    localMax = Math.max(num, localMax + num); \n    globalMax = Math.max(localMax, globalMax); \n  });\n  \n  /**\n   * After 2x concatenations, the only increments we can gain\n   * are from the total sum of the array, if total sum is positive.\n   *\n   * @example: [1,-2, 1, 1], k=4.\n   * Total sum is 1 and concat 2x [1,-2,1,1,1,-2,1,1] max is 3.\n   * From max 2x concat=3, each successive concat k after 2, we gain totalSum 1.\n   * i.e max2x + (k-2)*totalSum = (3 + (4-2)*1) = (3+ ((2)*1) = 5)\n   */\n  if (totalSum > 0) {\n    globalMax += (k - 2) * totalSum;\n  }\n  \n  return globalMax % MOD;\n};\n```\n\n---\n\n> **Shorter commentary for code legibility:**\n\n```js\nvar MOD = 1000000007;\n\nvar kConcatenationMaxSum = function(arr, k) {\n  var totalSum = 0;\n  var localMax = 0;\n  var globalMax = 0;\n  \n  // Kadane\'s with addition of calc total sum.\n  arr.forEach((num) => {\n    totalSum += num;\n    localMax = Math.max(num, localMax + num);\n    globalMax = Math.max(localMax, globalMax); \n  });\n  \n  // Don\'t need second concat if all negative\n  if (k === 1 || globalMax === 0) {\n    return globalMax % MOD;\n  }\n  \n  // Calc max subarray sum with k=2\n  arr.forEach((num) => {\n    localMax = Math.max(num, localMax + num); \n    globalMax = Math.max(localMax, globalMax); \n  });\n  \n  // Answer is maxSubSumK2 + (totalSum + (k-2)) if totalSum > 0\n  return globalMax + Math.max((k - 2) * totalSum, 0) % MOD;\n};\n```
['JavaScript']