Tag: programming
-
Rotate array [LC150]
Hello friends, Today we’re going to discuss and solve another Leetcode DSA problem about rotating array. link- https://leetcode.com/problems/rotate-array/description/ Given an integer array nums, rotate the array to the right by k steps, where k is non-negative. Example 1: Input: nums = [1,2,3,4,5,6,7], k = 3, Output: [5,6,7,1,2,3,4]Explanation:rotate 1 steps to the right: [7,1,2,3,4,5,6]rotate 2 steps…
-
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 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…
-
Merge Sorted Array [LC150]
Hello friends, Today we are going to solve another leetcode problem about merging sorred array. Link- https://leetcode.com/problems/merge-sorted-array/description/ You have two integer arrays, nums1 and nums2, which are sorted from smallest to largest. You also have two numbers, m and n, which show how many elements are in nums1 and nums2 respectively. Your goal is 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…
-
Moore Majority Vote Algorithm [LC150]
Hello friends, Hope you’re doing well. Today we are going to discuss an important algo in software engineering called “Moore Majority vote”. We shall also try to implement it in C#. Let’s first talk about background work that is done prior to this algo and then we shall understand how it’s useful. Let’s take an…
-
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…
