View algorithms on Arrays
Given a sorted array and a target element, find its first and last index.
View algorithms on Arrays
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.
A queue is a linear data structure which maintains the order in which the elements appear. You need to implement a queue, using two stacks such that it behaves in the same way. If you are unfamiliar with the queue data structure and the stack data structure, it would be a good idea to learn them before approaching this problem. Problem Statement: The basic crux of the problem is that you are to implement a queue and its operations using stacks. It may seem unnecessary in the beginning, as a…
An array is the most basic data structure one can think of. It may seem very easy to use and in a lot of my posts we have been solving problems using arrays. However, if you are just getting started with programming this post is probably for you. I would like to cover some of the basic concepts that makes this data structure so desirable and easy to use. If you have been programming for a while now this post is probably not written for you. Read along keeping that…
Question: You will be given two arrays of integers and asked to determine all integers between two sets that satisfy the following two conditions:– The elements of the first array are all factors of the integer being considered– The integer being considered is a factor of all elements of the second array Input:a = { 2, 6 }b = { 24, 36 } Output:2 I really want to simplify this really confusing problem statement first. The hardest part about this problem is to understand what is it actually saying. To…
Question: Given an array of integers, find the number of pairs of array elements that have a difference equal to the target value. Example: Input:arr[ ] = {1, 2, 3, 4}k = 1 Output: 3 Problem Statement Let us try to simplify the problem statement first and understand the sample test case. You are given an array of unique integers which is in any random order. Along with the array, you are also given a target value k. If you pick up any 2 integers from the array, they would…