scala greedy solution (sort + fold)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nobject Solution {\n    val minValue = -Math.pow(10, 9) - 1 // max value of w is 10^9\n    def minRectanglesToCoverPoints(points: Array[Array[Int]], w: Int): Int = {\n        points\n            .map(_.head)\n            .sorted\n            .foldLeft((this.minValue, 0)) {\n                case ((x1, count), x2) => {\n                    if x2 - x1 <= w then (x1, count)\n                    else (x2, count + 1)\n                }\n            }\n            ._2\n    }\n}\n```
['Scala']