## Find Smallest Range Containing Elements from k Lists

In the problem “Find the smallest range containing elements from k lists” we have given K lists which are sorted and of the same size N. It asks to determine the smallest range that contains at least element(s) from each of the K lists. If there is more than one …

## Queries for Number of Distinct Elements in a Subarray

We have given an array of integer and a number of queries and we have to find out the number of all the distinct elements we have within the given range, the query consists of two numbers left and right, this is the given range, with this given range we …

## Queries on Probability of Even or Odd Number in given Ranges

We have given an array of integer, q number of queries. Where each query contains three integers, which defines a type of query. This means if we have given 0 it means we have to find the probability of choosing an odd number in the given range. Where the range …

## Count and Toggle Queries on a Binary Array

An array of size n has been given as an input value. The problem “Count and Toggle Queries on a Binary Array” asks to perform some of the queries which are given below, queries can vary in a random manner. The queries are ⇒ Toggle query ⇒ toggle(starting, ending), this …

## Find First and Last Position of Element in Sorted Array Leetcode Solution

Problem statement In this article titled “Find First and Last Position of Element in Sorted Array Leetcode Solution,” we will discuss the solution to a leetcode problem. In the given problem we are given an array. We are also given a target element. Elements in the array are sequenced in …

## Maximum number of segments of lengths a, b and c

The problem “Maximum number of segments of lengths a, b and c” states that you are given a positive integer N, and you need to find the maximum number of segments of lengths a,b, and c that can be formed using N. Example N = 7 a = 5, b …

## LCS (Longest Common Subsequence) of three strings

The problem “LCS (Longest Common Subsequence) of three strings” states that you are given 3 strings. Find out the longest common subsequence of these 3 strings. LCS is the string that is common among the 3 strings and is made of characters having the same order in all of the …

## Best Time to Buy and Sell Stock  II Leetcode Solution

Problem statement In the problem “Best Time to Buy and Sell Stock  II,” we are given an array where each element in the array contains the price of the given stock on that day. The definition of the transaction is buying one share of stock and selling that one share …

## Count ways to reach the nth stair using step 1, 2 or 3

The problem “Count ways to reach the nth stair using step 1, 2, or 3” states that you are standing on the ground. Now you need to reach the end of the staircase. So how many ways are there to reach the end if you can jump only 1, 2, …

## Iterative Preorder Traversal

The problem “Iterative Preorder Traversal” states that you are given a binary tree and now you need to find the preorder traversal of the tree. We are required to find the preorder traversal using iterative method and not the recursive approach. Example   5 7 9 6 1 4 3 …