aboutsummaryrefslogtreecommitdiff
path: root/max_fruits_harvested_k_step.c
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2025-08-03 11:22:39 +0100
committerJack Sangdahl <[email protected]>2025-08-03 11:22:39 +0100
commit23f4ec5bfd6efc70417e3952217e11efd75b9d23 (patch)
treef31f5f9980a940b6c297177fe3e2043763f70ddd /max_fruits_harvested_k_step.c
parent0025b8254ac7fd37f1c82686f3cb728e1ef2e1fe (diff)
downloadleetcode-23f4ec5bfd6efc70417e3952217e11efd75b9d23.tar.gz
leetcode-23f4ec5bfd6efc70417e3952217e11efd75b9d23.zip
2106. maximum fruits harvested after at most k steps
Diffstat (limited to 'max_fruits_harvested_k_step.c')
-rw-r--r--max_fruits_harvested_k_step.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/max_fruits_harvested_k_step.c b/max_fruits_harvested_k_step.c
index c5a2778..47776de 100644
--- a/max_fruits_harvested_k_step.c
+++ b/max_fruits_harvested_k_step.c
@@ -123,14 +123,20 @@ int maxTotalFruits(int **fruits, int fruitsSize, int *fruitsColSize,
}
int main() {
- int f1[3][2] = {{2, 8}, {6, 3}, {8, 6}},
- f2[6][2] = {{0, 9}, {4, 1}, {5, 7}, {6, 2}, {7, 4}, {10, 9}},
- f3[3][2] = {{0, 3}, {6, 4}, {8, 5}};
- int fcs1 = ARRAY_SIZE(f1), fcs2 = ARRAY_SIZE(f2), fcs3 = ARRAY_SIZE(f3);
- printf("%d\n", maxTotalFruits((int **)f1, ARRAY_SIZE(f1[0]), &fcs1, 5,
- 4)); // expect: 9
- printf("%d\n", maxTotalFruits((int **)f2, ARRAY_SIZE(f2[0]), &fcs2, 5,
- 4)); // expect: 14
- printf("%d\n", maxTotalFruits((int **)f3, ARRAY_SIZE(f3[0]), &fcs3, 3,
- 2)); // expect: 0
+ int f1i[3][2] = {{2, 8}, {6, 3}, {8, 6}},
+ f2i[6][2] = {{0, 9}, {4, 1}, {5, 7}, {6, 2}, {7, 4}, {10, 9}},
+ f3i[3][2] = {{0, 3}, {6, 4}, {8, 5}};
+ struct two_d_arr f1, f2, f3;
+ two_d_arr_init(&f1, ARRAY_SIZE(f1i), ARRAY_SIZE(f1i[0]), f1i);
+ two_d_arr_init(&f2, ARRAY_SIZE(f2i), ARRAY_SIZE(f2i[0]), f2i);
+ two_d_arr_init(&f3, ARRAY_SIZE(f3i), ARRAY_SIZE(f3i[0]), f3i);
+ printf("%d\n",
+ maxTotalFruits(f1.arr, f1.row_size, f1.col_size, 5, 4)); // expect: 9
+ printf("%d\n",
+ maxTotalFruits(f2.arr, f2.row_size, f2.col_size, 5, 4)); // expect: 14
+ printf("%d\n",
+ maxTotalFruits(f3.arr, f3.row_size, f3.col_size, 3, 2)); // expect: 0
+ two_d_arr_free(&f1);
+ two_d_arr_free(&f2);
+ two_d_arr_free(&f3);
}