Aws
Auth
Axios
Admin
Angular
Android
Atom Payment
BPO
BcryptJs
Bootstrap
Basic Computer
C Language
C++
Css
Canva
Common questions
CorelDraw
Cloudinary
Content Writer
DSA
Django
Error
Excel
ExpressJs
Flutter
Github
Graphql
GoDaddy
HR
Html5
Hostinger
Jwt
Java
Json
Jquery
Javascript
Linux OS
Loopback API
MySQL
Manager
MongoDB
Marketing
MS Office
Mongoose
NodeJs
NextJs
Php
Python
Photoshop
PostgreSQL
PayU Payment
Paypal Payment
Redux
ReactJs
Router
React Native
React Router Dom
React Helmet
Sass
SEO
SMO
Stripe Payment
System Administrator
Software Testing
Typescript
Tailwind
Telesales
Tally
VueJs
Windows OS
XML
Description : Find all start indices of anagrams of a pattern in a string.
Use a sliding window and hash maps to compare character counts. Slide the window across the string and check if the counts match. For example, in 'cbaebabacd' with pattern 'abc', the start indices of anagrams are 0 and 6.
Category : DSA
Created Date : 9/12/2024
Find the Maximum Subarray Sum
Use Kadane's Algorithm to find the maximum sum. Initialize the maximum sum and current sum as the first element, then iterate through the array updating these values. For example, for [1, -2, 3, 4, -1], the maximum subarray sum is 7.
Use Kadane's Algorithm to find the maximum sum. Initialize the maximum sum and current sum as the first element, then iterate through the array updating these values. For example, for [1, -2, 3, 4, -1], the maximum subarray sum is 7.
Find All Anagrams in a String
Use a sliding window and hash maps to compare character counts. Slide the window across the string and check if the counts match. For example, in 'cbaebabacd' with pattern 'abc', the start indices of anagrams are 0 and 6.
Use a sliding window and hash maps to compare character counts. Slide the window across the string and check if the counts match. For example, in 'cbaebabacd' with pattern 'abc', the start indices of anagrams are 0 and 6.
Find the Longest Palindromic Substring
Use a dynamic programming approach to build a table that tracks palindromic substrings. For example, in 'babad', the longest palindromic substring is 'bab' or 'aba'.
Use a dynamic programming approach to build a table that tracks palindromic substrings. For example, in 'babad', the longest palindromic substring is 'bab' or 'aba'.
Implement Depth-First Search
DFS explores as far as possible along each branch before backtracking. Use a stack or recursion to keep track of nodes. For example, in a graph with nodes 1 -> 2 -> 3, DFS from 1 explores 1, 2, and then 3.
DFS explores as far as possible along each branch before backtracking. Use a stack or recursion to keep track of nodes. For example, in a graph with nodes 1 -> 2 -> 3, DFS from 1 explores 1, 2, and then 3.
Detect a Cycle in a Directed Graph
Use Depth-First Search with a tracking mechanism for visited nodes. If a node is revisited during the same DFS traversal, a cycle exists. For example, in a graph with edges 1 -> 2 -> 3 -> 1, a cycle is detected.
Use Depth-First Search with a tracking mechanism for visited nodes. If a node is revisited during the same DFS traversal, a cycle exists. For example, in a graph with edges 1 -> 2 -> 3 -> 1, a cycle is detected.
Find the Kth Largest Element in an Array
Use a min-heap of size K to keep track of the K largest elements. For each element, if it is larger than the smallest element in the heap, replace the smallest. For example, in [3, 2, 1, 5, 6, 4], the 2nd largest element is 5.
Use a min-heap of size K to keep track of the K largest elements. For each element, if it is larger than the smallest element in the heap, replace the smallest. For example, in [3, 2, 1, 5, 6, 4], the 2nd largest element is 5.
Find the Shortest Path in an Unweighted Graph
Use BFS to explore the shortest path in an unweighted graph. Enqueue the starting node, then visit each neighbor while updating distances. For example, in a graph with edges (1 -> 2), (2 -> 3), (1 -> 3), the shortest path from 1 to 3 is 1 -> 3.
Use BFS to explore the shortest path in an unweighted graph. Enqueue the starting node, then visit each neighbor while updating distances. For example, in a graph with edges (1 -> 2), (2 -> 3), (1 -> 3), the shortest path from 1 to 3 is 1 -> 3.
Implement a Priority Queue
A priority queue can be implemented using a heap where the highest (or lowest) priority element is always at the top. Operations include insert and extract-max (or extract-min). For example, in a max-heap, inserting 5 and 10 results in [10, 5].
A priority queue can be implemented using a heap where the highest (or lowest) priority element is always at the top. Operations include insert and extract-max (or extract-min). For example, in a max-heap, inserting 5 and 10 results in [10, 5].
Implement Breadth-First Search
BFS explores all neighbors of a node before moving to the next level. Use a queue to keep track of nodes. For example, in a graph with nodes 1 -> 2 -> 3, BFS from 1 explores 1, then 2 and 3.
BFS explores all neighbors of a node before moving to the next level. Use a queue to keep track of nodes. For example, in a graph with nodes 1 -> 2 -> 3, BFS from 1 explores 1, then 2 and 3.
Find the Longest Common Subsequence
Use dynamic programming to build a table where each cell represents the length of the longest common subsequence up to those indices. For example, for 'abcde' and 'aceb', the longest common subsequence is 'ace' with length 3.
Use dynamic programming to build a table where each cell represents the length of the longest common subsequence up to those indices. For example, for 'abcde' and 'aceb', the longest common subsequence is 'ace' with length 3.
Find the Longest Path in a Directed Acyclic Graph
Use topological sorting to order nodes and then apply dynamic programming to find the longest path. For example, in a DAG with edges 1 -> 2, 1 -> 3, 2 -> 4, 3 -> 4, the longest path is 1 -> 2 -> 4 or 1 -> 3 -> 4.
Use topological sorting to order nodes and then apply dynamic programming to find the longest path. For example, in a DAG with edges 1 -> 2, 1 -> 3, 2 -> 4, 3 -> 4, the longest path is 1 -> 2 -> 4 or 1 -> 3 -> 4.
Find the First Non-Repeating Character in a String
Use a hash map to count the frequency of each character, then iterate through the string to find the first character with a count of 1. For example, in 'swiss', the first non-repeating character is 'w'.
Use a hash map to count the frequency of each character, then iterate through the string to find the first character with a count of 1. For example, in 'swiss', the first non-repeating character is 'w'.
Implement Binary Search
Binary search divides the search interval in half. Start with the middle element; if it matches the target, return it. Otherwise, adjust the search range to either the left or right half based on comparison. For example, searching for 4 in [1, 2, 3, 4, 5] returns index 3.
Binary search divides the search interval in half. Start with the middle element; if it matches the target, return it. Otherwise, adjust the search range to either the left or right half based on comparison. For example, searching for 4 in [1, 2, 3, 4, 5] returns index 3.
Find the Intersection of Two Linked Lists
Use two pointers to traverse the linked lists. When one pointer reaches the end, move it to the start of the other list. Continue until both pointers meet. For example, if lists intersect at node with value 8, both pointers will eventually reach this node.
Use two pointers to traverse the linked lists. When one pointer reaches the end, move it to the start of the other list. Continue until both pointers meet. For example, if lists intersect at node with value 8, both pointers will eventually reach this node.