Added sliding window
This commit is contained in:
@@ -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){};
|
||||
|
||||
Reference in New Issue
Block a user