View algorithms on Arrays
Given an array of positive integers with some zeroes. You need to move all the zeroes to the end without changing the relative order of non-zero elements. A unique solution makes this problem really easy to understand.
View algorithms on Arrays
Given an array of positive integers with some zeroes. You need to move all the zeroes to the end without changing the relative order of non-zero elements. A unique solution makes this problem really easy to understand.
Binary Search is a fabulous concept that can be used to narrow down the search range. One such problem on LeetCode explores this domain where you need to find the correct position to insert the element in a sorted array
Small problems like these often become a part of larger complex problems. You are given an array and for each integer you need to find out the number of smaller numbers than itself. One technique is to compare each element with every other element. Another efficient approach would be to use the counting sort approach.
Always make sure that we understand the problem statement first. There is an array of integers nums and we need to determine the number of good pairs. A pair (i , j ) is said to be good, if nums[i] == nums[j] and i < j. We need to determine how many pairs can we form that hold this condition. Let us look at some sample test cases: Input: nums = [ 1 , 2 , 3 , 1 , 1 , 3 ]Output: 4Explanation:There are 4 good pairs. (0…
Let us try to understand this problem statement first. It is actually very verbose. We will try to simplify it as much as possible. Christy wants to give chocolates to her colleagues, and at the same time tries to ensure that everyone has equal chocolates at the end. To achieve this she either gives 1,2, or 5 chocolates to everyone except any one individual. Every-time she does this, it is counted as 1 operation. We need to make sure that Christy can achieve this task in the minimum number of…
Given an array of integers, find the elements that appear twice. The main challenge of this problem is to solve it without using any extra space. You need to find a way to mark the elements that are already encountered. Once such way would be to make the elements negative. This post gives you 2 different solutions a video explanation.
You are in charge of birthday cake candles at a party. However, the child can only blow out the tallest candles.
Read this post to know how you can find out the number of candles that get blown out along with the full implementation.
You are given an array that is sorted but also rotated by an unknown number of times. Given a target value, return the index if it can be found. In this post we discuss the solution to this problem using a modified version of the binary search technique.