Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 292c6d1

Browse files
2975. Maximum Square Area by Removing Fences From a Field
1 parent 1f4eb22 commit 292c6d1

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class Solution {
2+
3+
// Solution by Sergey Leschev
4+
// 2975. Maximum Square Area by Removing Fences From a Field
5+
6+
func maximizeSquareArea(_ m: Int, _ n: Int, _ hFences: [Int], _ vFences: [Int]) -> Int {
7+
let mod = Int(1e9 + 7)
8+
var ans: Int64 = 0
9+
var st = Set<Int>()
10+
11+
var updatedHFences = hFences
12+
var updatedVFences = vFences
13+
14+
updatedHFences.append(1)
15+
updatedHFences.append(m)
16+
updatedVFences.append(1)
17+
updatedVFences.append(n)
18+
19+
for i in 0..<updatedHFences.count {
20+
for j in 0..<updatedHFences.count {
21+
st.insert(abs(updatedHFences[i] - updatedHFences[j]))
22+
}
23+
}
24+
25+
for i in 0..<updatedVFences.count {
26+
for j in 0..<updatedVFences.count {
27+
if i != j && st.contains(abs(updatedVFences[i] - updatedVFences[j])) {
28+
ans = max(ans, Int64(abs(updatedVFences[i] - updatedVFences[j])))
29+
}
30+
}
31+
}
32+
33+
return ans == 0 ? -1 : Int((ans * ans) % Int64(mod))
34+
}
35+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /