You may be wondering why are we discussing this approach when it is not efficient enough. There exists an inefficient but simple approach to solving this problem. Out of all these calculated sums, the maximum sum is 40. Now we calculate the sum of each block, the sum of each corresponding block is as follows: 37, 40, 39, 38. So, k is equal to 3 in this case.īlocks containing three consecutive entries in the given array are,. Suppose that the following array is given to us and we are required to find 3 consecutive numbers in this array that give us the largest sum. Not sure if you get it? Don’t worry we will understand this by taking an example. The problem statement is as follows, find the largest sum of K consecutive entries, given an array of size N. Let us first understand the problem before going further with its approach. In this article, we discuss what the Sliding Window Algorithm technique is and its implementation in Python, C++, and Java. The Sliding Window Algorithm is one such popular algo, which has its use in cases across fields like computer networks and data communication. If you study Computer Science, you are bound to come across various algorithms.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |