# Scala Solutions with Runtime limits exceeds....

• Step 1: group points by (x,y) pair
Step 2: calculate every point pair's area = (y2 - y1) * (x2 - x1)
Step 3: calculate leftBottomPoint * rightTopPoint = totalArea
Step 4: these 2 areas should equal each other.

class defination

'''
case class Point(x:Int, y:Int) {

`````` def <=(that:Point): Boolean = {
this.x <= that.x && this.y <= that.y
}

def >=(that:Point): Boolean = {
this.x >= that.x && this.y >= that.y
}

def *(that:Point):Int = {
Math.abs(this.x - that.x) * Math.abs(this.y - that.y)
}
``````

}

'''
object LC392Solution {

def isRectangleCover(rectangles: Array[Array[Int]]): Boolean = {

``````   val points = ListBuffer[Point]()

rectangles.map( arr => {

for (i <- 0 until arr.length by 2) {
val p = Point(arr(i),arr(i + 1))
points += p
}
})

//find leftBottomPoint and rightBottomPoint
var sumOfArea = 0

for ( i <- 0 until points.length by 2) {

var p1 = points(i)
var p2 = points(i + 1)

val d = p1 * p2
sumOfArea += d
}

var leftBottomPoint = points(0)
var rightTopPoint = points(0)

points.map (p => {

if (leftBottomPoint >= p) {
leftBottomPoint = p
}

if (rightTopPoint <= p) {
rightTopPoint = p
}
})

val mostSumOfArea = leftBottomPoint * rightTopPoint

mostSumOfArea == sumOfArea
``````

}

}

'''

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.