GFG : Max Sum Subarray of size K
Problem: Given an array of integers Arr of size N and a number K. Return the maximum sum of a subarray of size K. NOTE*: A subarray is a contiguous part of any given array. Solution:
Learn to Code and Code to Learn
Your Journey to Code Mastery
Problem: Given an array of integers Arr of size N and a number K. Return the maximum sum of a subarray of size K. NOTE*: A subarray is a contiguous part of any given array. Solution:
Problem Given an array A[] of size N and a positive integer K, find the first negative integer for each and every window(contiguous subarray) of size K. Solution-1 Solution-2
Problem : Given an array of integers and a number K. Find the count of distinct elements in every window of size K in the array. Solution:
Problem : Due to the rise of covid-19 cases in India, this year BCCI decided to organize knock-out matches in IPL rather than a league. Today is matchday 2 and it is between the most loved team Chennai Super Kings and the most underrated team – Punjab Kings. Stephen Fleming, the head coach of CSK, analyzing the…
Problem : You are given an array prices where prices[i] is the price of a given stock on the ith day. You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock. Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0. Solution…
Problem: You are given an integer array nums and an integer k. Find the maximum subarray sum of all the subarrays of nums that meet the following conditions: The length of the subarray is k, andAll the elements of the subarray are distinct.Return the maximum subarray sum of all the subarrays that meet the conditions….
Read More “LeetCode : 2461. Maximum Sum of Distinct Subarrays With Length K” »
Problem: You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position. Return the max sliding…
Sliding window technique is used to reduce the use of nested loops and replace it with a single loop, thereby reducing the time complexity. Hand written notes
1.Sliding Window Usage: This algorithmic technique is used when we need to handle the input data in a specific window size. DS Involved: Array, String, HashTable Sample Problems: Longest Substring with ‘K’ Distinct Characters Fruits into Baskets 2. Islands (Matrix Traversal) Usage: This pattern describes all the efficient ways of traversing a matrix (or 2D…
Read More “Top 20 coding patterns to master MAANG Interview” »
Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1. You must write an algorithm with O(log n) runtime complexity. Example 1: Input: nums = [-1,0,3,5,9,12], target = 9 Output: 4 Explanation: 9 exists in nums and its index is 4 Example…