C++ Simple Explanation | Clean Code | O(NlogN) time, O(1) space
just try to dry run this after reading this explanation!\non this example\n\n[1,2,4,9,10,11]\n\nAfter sorting the array what we basically try to do is traverse 
just try to dry run this after reading this explanation!\non this example\n```\n[1,2,4,9,10,11]\n```\nAfter sorting the array what we basically try to do is traverse the array and in each iteration we check whether its possible to move ahead. If yes we do otherwise we simply break.\n\n1. the ``sum`` variable basically depicts the max value that it is possible to reach so far. So intially it\'s intialised with zero.\n2. After that we start traversing the array\n3. At every step we check that wether we have created all the numbers ``>= current_number-1``, because all the numbers from the ( ``current_number`` to ``current_number+sum`` ) can be created with the help of this ``current_number``. Thus after ensuring that all those numbers can be created (just checking ``sum >= curr - 1`` ), we can simply update our ``sum`` variable and move to the next iteration. If it\'s  not valid to move forward we simply break.\n4. We simply return ``sum+1`` (the +1 just to account ``0`` that has to be counted extra)\n\nTime Complexity:  `O(NlogN)`, just sorting and then a single traversal.\nSpace Complexity: `O(1)`, as we are using no extra arrays, just some variables.\n\n**Please Upvote if you liked the solution and it helped you!!\u2764\uFE0F\uD83D\uDE03\uD83D\uDC4D**\n\n**C++**\n```\nclass Solution {\npublic:\n    int getMaximumConsecutive(vector<int>& coins) {\n      int n = coins.size();\n      int sum = 0;\n      sort(coins.begin(), coins.end());\n      for(int i = 0; i < n; i++) {\n        int curr = coins[i];\n        if(sum >= (curr-1)) {\n          sum += curr;\n        }else {\n          break;\n        }\n      }\n      return sum+1;\n    }\n};\n```\n**Javascript**\n```\nfunction compare(a, b) {\n    if(a > b) return 1;\n    if(a < b) return -1;\n    return 0;\n}\nvar getMaximumConsecutive = function(coins) {\n  const n = coins.length\n  let sum = 0\n  coins.sort(compare)\n  coins.forEach((coin) => {\n    if(sum >= coin-1) {\n      sum += coin\n    }else {\n      return sum + 1;\n    }\n  })\n  return sum + 1;\n};\n```\n
['Greedy', 'Sorting']