Max Average Subarray in Java with Sliding Window Technique

100 Days of Coding Challenge – Day 27 📌 Problem: Maximum Average Subarray I 💻 Language: Java 🧠 Concept Used: Sliding Window Technique 🔍 Platform: LeetCode Today’s challenge was to find a contiguous subarray of length k that has the maximum average value. Example: Input: [1,12,-5,-6,50,3], k = 4 Output: 12.75 Approach: ✔ Calculate the sum of the first window of size k ✔ Slide the window by removing the left element and adding the next element ✔ Keep track of the maximum sum ✔ Divide by k to get the maximum average Time Complexity: O(n) Space Complexity: O(1) 🔗 Problem Link: https://lnkd.in/ghU4zrpt 🔗 Code: https://lnkd.in/g7qXeHx6 #100DaysOfCode #Day27 #Java #DSA #LeetCode #SlidingWindow #Arrays #ProblemSolving #CodingJourney

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories