Added sliding window

This commit is contained in:
2024-10-30 17:49:58 -04:00
parent 65996765d1
commit c2bdd92ec4
5 changed files with 102 additions and 3 deletions

View File

@@ -32,6 +32,20 @@ TEST(ChapterOne, CheckPermutations){
}
TEST(ChapterOne, SubArraySum){
// Not actually in CTCI but is related to arrays
// Prompt: Given an array, find the sum of all subarrays of length K
// (fixed sliding window)
int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
CHECK_EQUAL(27, sliding_window_max_sum(a1, 11, 3));
// Prompt: Find the shortest subarray with a sum greater than or
// equal to X (dynamic sliding window)
int a2[] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
CHECK_EQUAL(1, sliding_window_shortest_subarray(a2, 9, 7));
}
// Chapter 2: Linked Lists ___________________________________________
TEST_GROUP(ChapterTwo){};