Tag: Algorithm
-
Remove duplicates from-sorted array-2 [LC150]
Hello friends, Today we’re going to discuss another Leetcode DSA problem about removing duplicates from-sorted array. link- https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/description/ Given an integer array nums sorted in non-decreasing order, remove some duplicates in-place such that each unique element appears at most twice. The relative order of the elements should be kept the same. To change the length of the array in some languages, you need to…
-
Remove duplicates from-sorted array [LC150]
Hello friends, Today we’re going to discuss another Leetcode DSA problem about removing duplicates from-sorted array. link- https://leetcode.com/problems/remove-duplicates-from-sorted-array/ Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Then return the number of…
-
Remove array element in-place [LC150]
Hello friends, Today we’re going to discuss another Leetcode DSA problem about removing array element in-place. link- https://leetcode.com/problems/remove-element/description Given an integer array nums and an integer val, remove all instances of val from nums in place. The order of elements can be changed. Return the count of elements in nums that are not equal to…
-
Dutch National Flag algorithm
Hello folks, Hope you’re doing well. Today we shall discuss one of the important computer since algo called Dutch national flag. This is invented by a famous computer scientist Edsger Dijkstra. The Dutch/Netherlands flag consists of three colors: Red, Blue, and White. The objective of this algo to arrange these colors in order (in fastest…
-
Algorithm to get max profit from stock transactions [LC150]
Hello friends, Today let’s go over the algorithm to find maximum profit out of stock buy and sell. Let’s first understand the problem statement. 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. If you cannot achieve any profit, return…
-
Insert an element at specific array position
Hello friends, Let’s go through how can we add an element at specific array position. Let’s begin by adding the common code/caller. Common code: Now time has come to create basic method to allow insertion of any element in specific position. Approach-1 (Rudimentary)– Time complexity: O(n2) Now let’s refine the basic approach and find effective…
