ddhuuddhuu.hashnode.dev·Jul 19, 2024Mastering the Two Pointers TechniqueIntroduction The Two Pointers technique is a versatile and efficient method commonly used to solve various problems involving arrays, strings, and linked lists. This technique is particularly effective when dealing with pairs or sub-arrays that need ...Discuss·2 likesDSA
Akshaya Biswalakshaya-biswal.hashnode.dev·Jul 17, 2024Leetcode 1750: Minimum Length of String After Deleting Similar EndsTo find the minimum length of a string after deleting similar characters from both ends using a simple two-pointers approach in JavaScript Explanation Initialize two pointers, left starting from the beginning of the string and right starting from th...DiscussDSA Sheet2Articles1Week
Akshaya Biswalakshaya-biswal.hashnode.dev·Jul 16, 2024Leetcode 2963: Count the Number of Good PartitionsLeetcode Link This algorithm essentially finds the number of good partitions by leveraging the last occurrence indices of elements and a two-pointer technique to identify valid partition points, doubling the number of partitions each time a valid poi...DiscussDSA SheetJavaScript
Jay Choukseyjayjava.hashnode.dev·Jul 15, 2024Max Number of K-Sum PairsIntroduction Today, I tackled another intriguing problem from LeetCode 75: Max Number of K-Sum Pairs. This medium-level question requires an understanding of arrays and the two-pointer technique. The goal is to find the maximum number of operations y...DiscussJava
Akshaya Biswalakshaya-biswal.hashnode.dev·Jul 14, 2024Leetcode 1877: Minimize Maximum Pair Sum in ArrayLeetcode Link we need to pair the elements in a way that minimizes the maximum pair sum. Steps Sort the Array: First, sort the array in ascending order. Pair Elements: Pair the smallest element with the largest element, the second smallest with the...DiscussDSA Sheettwo pointers
Akshaya Biswalakshaya-biswal.hashnode.dev·Jul 14, 2024Leetcode 1498: Number of Subsequences That Satisfy the Given Sum ConditionLeetcode Link Code const MOD = 1e9 + 7; const pre_compute_powers = (length) => { const pow = Array(length).fill(1); for (let i = 1; i < length; i++) { pow[i] = (pow[i - 1] * 2) % MOD; } return pow; }; const num_of_subsequence = (array, ...DiscussDSA SheetJavaScript
Akshaya Biswalakshaya-biswal.hashnode.dev·Jul 14, 2024Leetcode 151: Reverse Words in a StringWe need to reverse the order of words in a given string. Code const reverse_words = (string) => { const string_trim = string.trim(); const string_array = string_trim.split(/\s+/); const string_reverse = string_array.reverse(); const string_jo...DiscussDSA SheetJavaScript
Jay Choukseyjayjava.hashnode.dev·Jul 14, 2024Container With Most WaterIntroduction Today, I tackled an interesting problem from LeetCode 75: Container With Most Water. This medium-level question requires knowledge of two pointers and greedy algorithms. It involves finding the maximum amount of water a container can sto...DiscussJava
Akshaya Biswalakshaya-biswal.hashnode.dev·Jul 14, 2024Leetcode 26: Remove Duplicates from Sorted ArrayTo remove duplicates from a sorted array in JavaScript, we can use a Two Pointer approach, which is efficient with a time complexity of O(n). Code function removeDuplicates(array) { if (array.length === 0) return 0; let uniqueIndex = 0; for (...DiscussDSA Sheettwo pointers
Akshaya Biswalakshaya-biswal.hashnode.dev·Jul 13, 2024Leetcode 345. Reverse Vowels of a StringIn this article, we will talk about a JavaScript function called reverseVowels. This function takes a string and reverses the vowels in it. We will use the Two Pointers here. Code const vowels = "aeiouAEIOU"; const reverseVowels = (string) => { ...DiscussDSA SheetJavaScript