aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2025-08-25 20:29:36 -0600
committerJack Sangdahl <[email protected]>2025-08-25 20:29:36 -0600
commit93bbf9764ee8020da1c2914d16bc6c9698e3c329 (patch)
tree9dec46a4c310d9c68220ce687412c778473c4a20
parent98eef52499de73f369cc7e4a6e11938a1c6d3367 (diff)
downloadleetcode-93bbf9764ee8020da1c2914d16bc6c9698e3c329.tar.gz
leetcode-93bbf9764ee8020da1c2914d16bc6c9698e3c329.zip
3000. maximum area of longest diagonal rectangle
-rw-r--r--max_area_longest_diag_rect.c37
-rw-r--r--max_area_longest_diag_rect.py30
2 files changed, 67 insertions, 0 deletions
diff --git a/max_area_longest_diag_rect.c b/max_area_longest_diag_rect.c
new file mode 100644
index 0000000..3aa7c8e
--- /dev/null
+++ b/max_area_longest_diag_rect.c
@@ -0,0 +1,37 @@
+// 3000. Maximum Area of Longest Diagonal Rectangle
+#include "leetcode.h"
+
+/*
+ * you are given a 2d 0-indexed integer array 'dimensions'. for all indices 'i',
+ * '0 <= i < dimensions.size', 'dimensions[i][0]' represents the length and
+ * 'dimensions[i][1]' represents the width of the rectangle 'i'. return the area
+ * of the rectangle having the longest diagonal, return the area of the
+ * rectangle having the maximum area.
+ */
+
+int areaOfMaxDiagonal(int **dimensions, int dimensionsSize,
+ int *dimensionsColSize) {
+ int ans = 0, max = 0;
+ for (int i = 0; i < dimensionsSize; i++) {
+ int l = dimensions[i][0], w = dimensions[i][1];
+ int curr = l * l + w * w;
+ if (curr > max || (curr == max && l * w > ans)) {
+ max = curr;
+ ans = l * w;
+ }
+ }
+ return ans;
+}
+
+int main() {
+ int d1i[2][2] = {{9, 3}, {8, 6}}, d2i[2][2] = {{3, 4}, {4, 3}};
+ struct two_d_arr d1, d2;
+ two_d_arr_init(&d1, ARRAY_SIZE(d1i), ARRAY_SIZE(d1i[0]), d1i);
+ two_d_arr_init(&d2, ARRAY_SIZE(d2i), ARRAY_SIZE(d2i[0]), d2i);
+ printf("%d\n",
+ areaOfMaxDiagonal(d1.arr, d1.row_size, d1.col_size)); // expect: 48
+ printf("%d\n",
+ areaOfMaxDiagonal(d2.arr, d2.row_size, d2.col_size)); // expect: 12
+ two_d_arr_free(&d1);
+ two_d_arr_free(&d2);
+}
diff --git a/max_area_longest_diag_rect.py b/max_area_longest_diag_rect.py
new file mode 100644
index 0000000..7789f74
--- /dev/null
+++ b/max_area_longest_diag_rect.py
@@ -0,0 +1,30 @@
+# 3000. Maximum Area of Longest Diagonal Rectangle
+
+"""
+you are given a 2d 0-indexed integer array 'dimensions'. for all indices 'i',
+'0 <= i < dimensions.size', 'dimensions[i][0]' represents the length and
+'dimensions[i][1]' represents the width of the rectangle 'i'. return the area
+of the rectangle having the longest diagonal, return the area of the
+rectangle having the maximum area.
+"""
+
+
+class Solution(object):
+ def areaOfMaxDiagonal(self, dimensions):
+ """
+ :type dimensions: List[List[int]]
+ :rtype: int
+ """
+ ans, area = 0, 0
+ for l, w in dimensions:
+ curr = l * l + w * w
+ if curr > area or (curr == area and l * w > ans):
+ area = curr
+ ans = l * w
+ return ans
+
+
+if __name__ == "__main__":
+ obj = Solution()
+ print(obj.areaOfMaxDiagonal(dimensions=[[9, 3], [8, 6]]))
+ print(obj.areaOfMaxDiagonal(dimensions=[[3, 4], [4, 3]]))