-
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(l.begin(), l.end(), value) != l.end();…
-
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 …
-
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/ Brute Force: Here just like…
-
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 : -8 0 -6 -6First…
-
Trees
List of tree problems
Subscribe
Enter your email below to receive updates.