-
Continue reading →: Longest subarray with sum k
Problem statement: You are given an array and a number K, you need to find longest subarray whose sum is K. For example : Array : {2,1,3, 1,1,1}, K = 3 In this we have {2,1} {3} {1,1,1} 3 sub-arrays whose sum is 3, where {1,1,1} is the longest with…
-
Continue reading →: STL Cheatsheet
Data Structure Initialization Insertion Deletion Contains Other Important Methods Vector vector<int> v; v.push_back(value); v.emplace_back(value); v[index] = value; v.erase(iterator); find(v.begin(), v.end(), value) != v.end(); v.size(), v.clear(), v.front(), v.back(), v.at(index) Deque deque<int> d; d.push_back(value); d.push_front(value); d.pop_front(); find(d.begin(), d.end(), value) != d.end(); d.size(), d.clear(), d.front(), d.back(), d.at(index) List list<int> l; l.push_back(value); l.push_front(value); l.erase(iterator);…
-
find the maximum for each and every contiguous subarray of size K.
Published by
jdecodes
on
Continue reading →: find the maximum for each and every contiguous subarray of size K.https://www.geeksforgeeks.org/sliding-window-maximum-maximum-of-all-subarrays-of-size-k https://leetcode.com/problems/sliding-window-maximum/description Given an array and an integer K, find the maximum for each and every contiguous subarray of size K. Examples : Input: arr[] = {1, 2, 3, 1, 4, 5, 2, 3, 6}, K = 3 Output: 3 3 4 5 5 5 6Explanation: Maximum of 1, 2, 3 is 3 …
-
Continue reading →: Count Number of anagrams
Given a word pat and a text txt. Return the count of the occurrences of anagrams of the word in the text. Example 1: Input: txt = forxxorfxdofr pat = for Output: 3 Explanation: for, orf and ofr appears in the txt, hence answer is 3. https://www.geeksforgeeks.org/problems/count-occurences-of-anagrams5839 slight variation of the problem: https://leetcode.com/problems/find-all-anagrams-in-a-string/…
-
Continue reading →: First negative integer in every window of size k
Problem Statement: Given an array and a positive integer k, find the first negative integer for each window(contiguous subarray) of size k. If a window does not contain a negative integer, then print 0 for that window. Examples: Input : arr[] = {-8, 2, 3, -6, 10}, k = 2Output…
-
Continue reading →: Maximum sum of subarray of SIZe k
Refer to g4g: https://www.geeksforgeeks.org/find-maximum-minimum-sum-subarray-size-k/ Simple Solution to this problem can be a brute force where we can check all the K size subarrays. For example If input is 4, 2, 1, 7, 8, 1, 2, 8, 1, 0 and K 3 We can take 4, 2,1 2, 1, 7 1,…