var checkValidCuts = function (n, rectangles) {
const mapx = {}
const mapy = {}
for (const [x1, y1, x2, y2] of rectangles) {
if (x1 in mapx) {
mapx[x1] = Math.max(x2, mapx[x1])
} else {
mapx[x1] = x2
}
if (y1 in mapy) {
mapy[y1] = Math.max(y2, mapy[y1])
} else {
mapy[y1] = y2
}
}
let count = 0
let t1 = null
let t2 = null
for (const key in mapx) {
if (!t1 && !t2) {
t1 = Number(key)
t2 = mapx[t1]
} else {
if (key < t2) {
t2 = Math.max(t2, mapx[key])
} else {
count++
t1 = Number(key)
t2 = mapx[t1]
}
}
if (count === 2) return true
}
count = 0
t1 = null
t2 = null
for (const key in mapy) {
if (!t1 && !t2) {
t1 = Number(key)
t2 = mapy[t1]
} else {
if (key < t2) {
t2 = Math.max(t2, mapy[key])
} else {
count++
t1 = Number(key)
t2 = mapy[t1]
}
}
if (count === 2) return true
}
return false
}
console.log(
checkValidCuts(5, [
[1, 0, 5, 2],
[0, 2, 2, 4],
[3, 2, 5, 3],
[0, 4, 4, 5],
]),
)