Bird
0
0
DSA Cprogramming~30 mins

Sliding Window on Arrays in DSA C - Build from Scratch

Choose your learning style9 modes available
Sliding Window on Arrays
📖 Scenario: Imagine you are analyzing daily temperatures over a week. You want to find the highest temperature recorded in every 3-day period to understand short-term heat waves.
🎯 Goal: Build a program that uses the sliding window technique to find the maximum temperature in every 3-day window from a list of daily temperatures.
📋 What You'll Learn
Create an array called temperatures with exactly these values: 30, 32, 31, 35, 33, 34, 36
Create an integer variable called window_size and set it to 3
Use a for loop with variable i to slide the window over the array and find the maximum temperature in each window
Print the maximum temperatures for each 3-day window separated by spaces
💡 Why This Matters
🌍 Real World
Sliding window technique is used in weather data analysis, stock price monitoring, and network traffic analysis to find trends over fixed-size periods.
💼 Career
Understanding sliding window helps in roles like data analysis, software development, and system monitoring where processing continuous data streams efficiently is important.
Progress0 / 4 steps
1
Create the temperatures array
Create an integer array called temperatures with these exact values: 30, 32, 31, 35, 33, 34, 36
DSA C
Hint

Use curly braces {} to list the values inside the array.

2
Set the window size
Create an integer variable called window_size and set it to 3
DSA C
Hint

Use int window_size = 3; to set the window size.

3
Find maximum in each sliding window
Use a for loop with variable i to slide the window over temperatures and find the maximum temperature in each window of size window_size. Store the maximum in a variable called max_temp inside the loop.
DSA C
Hint

Use a nested loop: outer loop slides the window, inner loop finds the max in the window.

4
Print the maximum temperatures
Inside the outer for loop, print the variable max_temp followed by a space. After the loop, print a newline character.
DSA C
Hint

Use printf("%d ", max_temp); inside the loop and printf("\n"); after the loop.