Menu
Coddy logo textTech

Practice #2

Lesson 10 of 12 in Coddy's Queue - Data Structures Series #2 course.

The next challenges are designed to use a queue. The Queue data structure is already provided for you — use it!

challenge icon

Challenge

Easy

Write a function named maxWindowSum that gets an array of integers (a) and a sliding window size (k), and returns the maximum sum in the sliding window.

Use the provided Queue to solve this problem!

Try it yourself

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "solution.h"

int main() {
    char line[4096];
    int* a = (int*)malloc(sizeof(int) * 1000);
    int aSize = 0;
    if (fgets(line, sizeof(line), stdin)) {
        char* tok = strtok(line, " \t\r\n");
        while (tok) { a[aSize++] = atoi(tok); tok = strtok(NULL, " \t\r\n"); }
    }
    int k = 0;
    scanf("%d", &k);
    printf("%d\n", maxWindowSum(a, aSize, k));
    free(a);
    return 0;
}

All lessons in Queue - Data Structures Series #2