Kotlin: Simple solution with comments
\nclass Solution {\n    fun insert(intervals: Array<IntArray>, newInterval: IntArray): Array<IntArray> {\n        \n\n        var ans = mutableListOf<IntArray>(
```\nclass Solution {\n    fun insert(intervals: Array<IntArray>, newInterval: IntArray): Array<IntArray> {\n        \n\n        var ans = mutableListOf<IntArray>()\n        \n        \n        var start = newInterval[0]\n        var end = newInterval[1]\n        \n        var counter = 0\n        \n        // get the intervals which are smaller than the newInterval\n        while(counter < intervals.size && intervals[counter][1] < start) ans.add(intervals[counter++])\n        \n        // check if any overlapping exist and define the boundraies for the merged intervals\n        while(counter < intervals.size && intervals[counter][0] <= end){\n            start = Math.min(intervals[counter][0],start)\n            end = Math.max(intervals[counter++][1],end)\n        }\n        \n        // add the merged intervals\n        ans.add(intArrayOf(start,end))\n        \n        // add the remaining part that its size is larger than the merged part\n        while(counter < intervals.size) ans.add(intervals[counter++])\n\n        return ans.toTypedArray()\n\n    }\n    \n}\n```
['Kotlin']