# Category: Arrays

## Dynamic Programming – Longest Common Subsequence

Objective: Given two string sequences, write an algorithm to find the length of longest subsequence present in both of them. These kind of dynamic programming questions are very famous in the interviews like Amazon,...

## Dynamic Programming – Minimum Cost Path Problem

Objective: Given a 2D-matrix where each cell has a cost to travel. You have to write an algorithm to find a path from left-top corner to bottom-right corner with minimum travel cost. You can...

## Dynamic Programming – Longest Increasing Subsequence

Objective: The longest Increasing Subsequence (LIS) problem is to find the length of the longest subsequence in a given array such that all elements of the subsequence are sorted in increasing order. OR Given...

## Backtracking – N Queens Problem – Better Solution

Objective : In chess, a queen can move as far as she pleases, horizontally, vertically, or diagonally. A chess board has 8 rows and 8 columns. The standard 8 by 8 Queen’s problem asks...

## Find the Kth Smallest/Largest Element in an Array

Objective: Given an array of integers. find the Kth Smallest/largest element in the array. Example: int[] A = { 1, 2, 10, 20, 40, 32, 44, 51, 6 }; K=4. 4th smallest element in...

## Priority Queue in Data Structure

Earlier in we have seen Min-Heap and Max-Heap Implementation. Priority Queue is its built-in implementation in Java. In this article we will see how to perform Min-Heap and Max-Heap using Priority Queue. Brief: A...

## Find the Second Largest Element in an Array

Objective: Given an array of integers. find the second largest element in the array. Example: int[] A = { 1, 2, 10, 20, 40, 32, 44, 51, 6 }; Second largest Element : 44...

## Merge K Sorted Arrays

Objective: Given k sorted array, write an algorithm to merge Them into One sorted array. Example : int[][] A = new int[5][]; A[0] = new int[] { 1, 5, 8, 9 }; A[1] =...

## Find a Number occurring odd number of times in a Given array

Objective: Given a array of integers, in which every elements occurs even number of times except one number which occurs add number of times. Find out that number. Example:   int[] A = {...

## Rearrange the Array of Given Range N, such that A[i]=i

Algorithms – Rearrange the Array of Given Range N, such that A[i]=i. Objective: Given a array of length N, in which elements are in the range of 1 to N. All elements may not...

## Find a Missing Number From a Sequence of Consecutive Numbers | XOR Method

Input:  Array, arrA[] with a miss­ing num­ber and Range Out­put : miss­ing number Example: int A[] = { 1, 2, 7, 6, 3, 4 }; int range = 7; Output: MIssing No is :5 In...

## Binary Min – Max Heap

A binary heap is a heap data structure created using a binary tree. binary tree has two rules – Binary Heap has to be complete binary tree at all levels except the last level....

## Magic Index – Find Index In Sorted Array Such That A[i] = i.

Objective: Given a sorted array of distinct integers, Find the Magic index or Fixed point in the array. Magic Index or Fixed Point: Magic index or a Fixed point in an array is an...

## Find All the Well Ordered Permutations of a Given String.

Objective: Write an algorithm to Print All the Well Ordered Permutations of a Given String. What is Well Ordered String: When all the alphabets in a string occur in the increasing order irrespective of...

## Find Increasing Triplet Sub-sequence

Objective: Given an integer array A[1..n], find an instance of i,j,k where 0 < i < j < k <= n and A[i] < A[j] < A[k]. Example : int arrA[] = { 10,...