Top 100+ data structures and algorithms interview questions in java
Tags: java, algorithms, practice, datastructures
Published: 2019-04-13 19:46:07

---
title: Top 100+ data structures and algorithms interview questions in java
published: true
description: 
tags: #java #algorithms #practice #data_structures
---

<div dir="ltr" style="text-align: left;">

I have been posting <a href="https://java2blog.com/data-structures-java/" target="_blank" rel="noopener">data structure</a> and algorithms interview questions on various topics such as Array, Queue, Stack, Binary tree, LinkedList, String, Number, ArrayList, etc. So I am consolidating a list of programs to create an index post. I will keep adding links to this post whenever I add new programs. These are frequently asked Data Structure and algorithm interview questions.


If you want to practice and improve data structure and algorithm programs, this post will be very helpful to you. I will recommend you to try it yourself first and then check the solution.
<h2><span style="color: #800000;">Stack</span></h2>
<img class="aligncenter size-full wp-image-4004" src="https://java2blog.com/wp-content/uploads/2017/09/Stack.png" alt="Stack" width="530" height="396" />
<div>

<hr />

<h4 style="text-align: left;">Question 1:  Implement a stack using array.</h4>
You need to implement Stack using array. You need to write push and pop methods to demonstrate Stack behavior(Last In First Out).
<b>Solution </b>:<a href="http://www.java2blog.com/implement-stack-using-array-in-java.html" target="_blank" rel="noopener noreferrer"> Java Program to implement stack using array.</a>

<hr />

<h4 style="text-align: left;">Question 2: Implement a stack using Linked List :</h4>
You need to implement Stack using Linked List. You need to write push and pop methods to demonstrate Stack behavior(Last In First Out).
<b>Solution  </b>: <a href="http://www.java2blog.com/implement-stack-using-linked-list-in-java.html" target="_blank" rel="noopener noreferrer">Java Program to implement stack using Linked List</a>

<hr />

<h4 style="text-align: left;">Question 3:  Implement a stack using two queues .</h4>
You need to use two queues to implement stack behavior.You need to write push and pop methods to demonstrate Stack behavior(Last In First Out).
<b>Solution </b>:<a href="http://www.java2blog.com/implement-stack-using-two-queues-in-java.html" target="_blank" rel="noopener noreferrer"> Java Program to implement stack using two queues</a>

<hr />

<h4 style="text-align: left;">Question 4 : Sort an stack using another stack</h4>
You need to sort an stack using another stack. You can use push and pop operation of stack to do so,
<b>Solution </b>: <a href="http://www.java2blog.com/sort-stack-using-another-stack.html" target="_blank" rel="noopener noreferrer">Sort a stack using another stack.</a>
<h2><span style="color: #800000;">Queue</span></h2>
<img class="aligncenter size-full wp-image-4003" src="https://java2blog.com/wp-content/uploads/2017/09/Queue.png" alt="Queue" width="674" height="301" />

<hr />

<h4 style="text-align: left;">Question 5:  Implement Queue using Array in java.</h4>
You need to use array to implement queue.
<b>Solution </b>:<a href="https://java2blog.com/implement-queue-using-array-in-java/" target="_blank" rel="noopener noreferrer"> Implement Queue using Array in java</a>

<hr />

<h4 style="text-align: left;">Question 6:  Implement a stack using two queues .</h4>
You need to use Linked list to implement queue.
<b>Solution </b>:<a href="https://java2blog.com/implement-queue-using-linked-list-in-java/" target="_blank" rel="noopener noreferrer"> Java Program to implement queue using linked list</a>
<h2><span style="color: #800000;">Linked List</span></h2>

<hr />

<h4 style="text-align: left;">Question 7 : Implement singly linked list in java.</h4>
You need to implement singly linked list data structures.You need to write simple program to demonstrate insert , delete operations.
<div style="clear: both; text-align: center;"><a style="margin-left: 1em; margin-right: 1em;" href="https://4.bp.blogspot.com/-4VowsytKKXw/VcWkmtC4WSI/AAAAAAAAD2E/0PmX9VUjHhQOotuRV5Ne3mpdJ3eHfWkTwCPcB/s1600/LinkedListWithoutLoop.jpg"><img src="https://4.bp.blogspot.com/-4VowsytKKXw/VcWkmtC4WSI/AAAAAAAAD2E/0PmX9VUjHhQOotuRV5Ne3mpdJ3eHfWkTwCPcB/s640/LinkedListWithoutLoop.jpg" width="640" height="42" border="0" /></a></div>
<b>Solution </b>: <a href="http://www.java2blog.com/implement-singly-linked-list-in-java.html" target="_blank" rel="noopener noreferrer">Java program to implement singly linked list in java.</a>

<hr />

<h4 style="text-align: left;">Question 8: How to reverse linked list in java.</h4>
You need to write iterative and recursive solution to reverse linked list.
<b>Solution </b><a href="http://www.java2blog.com/how-to-reverse-linked-list-in-java.html" target="_blank" rel="noopener noreferrer">: Java program to reverse linked list in java.</a>

<hr />

<h4 style="text-align: left;">Question 9: How to find middle element of linked list.</h4>
You need to write java program to find middle element of linked list in most optimize way.
<div style="clear: both; text-align: center;"><a style="margin-left: 1em; margin-right: 1em;" href="https://3.bp.blogspot.com/-foKjwd459OI/VcWoTxo6SUI/AAAAAAAAD2Y/dLcoqXhuAAYla_z_glpCDiXOjlxAzPS2gCPcB/s1600/LinkedListWithMiddleElement.jpg"><img src="https://3.bp.blogspot.com/-foKjwd459OI/VcWoTxo6SUI/AAAAAAAAD2Y/dLcoqXhuAAYla_z_glpCDiXOjlxAzPS2gCPcB/s640/LinqkedListWithMiddleElement.jpg" width="640" height="42" border="0" /></a></div>
<b>Solution </b>: <a href="https://www.code2master.com/java/find-middle-element-linked-list-one-scan/" target="_blank" rel="noopener noreferrer">Java program to find middle element of linked list</a>.

<hr />

<h4 style="text-align: left;">Question 10 : How to find nth element from end of linked list .</h4>
You need to write java program to find nth  element of linked list in most optimize way.
In question 6, Node 7 is 3rd from last of linked list.
<b>Solution </b>:<a href="http://www.java2blog.com/find-nth-element-from-end-of-linked-list.html" target="_blank" rel="noopener noreferrer"> How to find nth element from end of linked list.</a>

<hr />

<h4 style="text-align: left;">Question 11 : How to detect a loop in linked list. If linked list has loop, find the start node for the loop.</h4>
You need to write a java program to detect whether any loop exists in linked list and if loop exists , you need to find start node for the linked list.
<b>Solution </b>: <a href="http://www.java2blog.com/how-to-detect-loop-in-linkedlist-in.html" target="_blank" rel="noopener noreferrer">How to detect loop in linked list</a>.
<a href="http://www.java2blog.com/find-start-node-of-loop-in-linkedlist.html" target="_blank" rel="noopener noreferrer">How to find start node of loop in linked list.</a>

<hr />

<h4 style="text-align: left;">Question 12: How to check if linked list is palindrome or not?</h4>
A palindrome is a word, phrase, number, or other sequence of symbols or elements that reads the same forward or reversed. For example: 12121 is palindrome as it reads same forward or reversed. madam is also a palindrome . So we need write java programs to check if linked list is palindrome or not.
<b>Solution </b>: <a href="http://www.java2blog.com/how-to-check-if-linked-list-is.html" target="_blank" rel="noopener noreferrer">Java program to check if linked list is palindrome.</a>

<hr />

<h4 style="text-align: left;">Question 13 :  Find intersection of two linked lists?</h4>
Given two <a href="https://java2blog.com/implement-singly-linked-list-in-java/" target="_blank" rel="noopener">singly linked lists</a>, find if two linked lists intersect. If they intersect, find intersection point.
<div style="clear: both; text-align: center;"><img class="aligncenter size-full wp-image-6348" src="https://java2blog.com/wp-content/uploads/2018/08/LinkedListIntersection.jpg" alt="" width="711" height="401" /></div>
Solution  : <a href="https://java2blog.com/intersection-two-linked-lists/" target="_blank" rel="noopener">Intersection of two linked list</a>

<hr />

<h4 style="text-align: left;">Question 14 :  How to reverse a linked list in pairs?</h4>
You need to write a java program to reverse linked list in pairs.
<div style="clear: both; text-align: center;"><a style="margin-left: 1em; margin-right: 1em;" href="https://1.bp.blogspot.com/-8N1scpgMXSQ/Vv7OSOBFbAI/AAAAAAAAEbI/4H2jGeVaK0Au9iyJ-ykRpTlgwJzft5kwQCPcB/s1600/ReverseLinkedListInPairs.png"><img src="https://1.bp.blogspot.com/-8N1scpgMXSQ/Vv7OSOBFbAI/AAAAAAAAEbI/4H2jGeVaK0Au9iyJ-ykRpTlgwJzft5kwQCPcB/s640/ReverseLinkedListInPairs.png" width="640" height="250" border="0" /></a></div>
Solution  : <a href="http://www.java2blog.com/java-program-to-reverse-linked-list-in.html" target="_blank" rel="noopener noreferrer">Java program to reverse linked list in pair.</a>

<hr />

<h4 style="text-align: left;">Question 15 :  Implement Doubly linked list in java?</h4>
You need to write a java program to implement doubly linked list in java.

<img class="aligncenter size-full wp-image-3900" src="https://java2blog.com/wp-content/uploads/2017/09/DoublyLinkedList.png" alt="Doubly Linked List in java" width="793" height="202" />
<div style="clear: both; text-align: center;"></div>
Solution  : <a href="https://java2blog.com/doubly-linked-list-java/" target="_blank" rel="noopener">Doubly Linked List in java</a>
<h2><span style="color: #800000;">Array</span></h2>
<img class="aligncenter size-full wp-image-4002" src="https://java2blog.com/wp-content/uploads/2017/09/Array.png" alt="Array" width="595" height="234" />

</div>
<div>

<hr />

<h4 style="text-align: left;">Question 16 : Write java Program to Find Smallest and Largest Element in an Array.</h4>
</div>
<div>You are given an integer array containing 1 to n but one of the number from 1 to n in the array is missing. You need to provide an optimum solution to find the missing number. Number can not be repeated in the arry.
For example:
<pre name="code" style="text-align: left;" class="">int[] arr1={7,5,6,1,4,2};
Missing numner : 3
int[] arr2={5,3,1,2};
Missing numner : 4</pre>
<b>Solution </b>: <a href="https://java2blog.com/java-program-to-find-smallest-and-largest-number-in-array/" target="_blank" rel="noopener noreferrer">Java Program to Find Smallest and Largest Element in an Array</a>

<hr />

<h4 style="text-align: left;">Question 17 : Find missing number in the array.</h4>
</div>
<div>You are given an integer array containing 1 to n but one of the number from 1 to n in the array is missing. You need to provide optimum solution to find the missing number. Number cannot be repeated in the arry.
For example:
<pre name="code" style="text-align: left;" class="">int[] arr1={7,5,6,1,4,2};
Missing numner : 3
int[] arr2={5,3,1,2};
Missing numner : 4</pre>
<b>Solution </b>: <a href="http://www.java2blog.com/java-program-to-find-missing-number-in-array.html" target="_blank" rel="noopener noreferrer">Find missing number in the array.</a>

<hr />

<h4 style="text-align: left;">Question 18 : Search an element in rotated and sorted array.</h4>
You are given an sorted and rotated array as below:
<pre name="code" class="">int arr[]={16,19,21,25,3,5,8,10};</pre>
If you note that array is sorted and rotated. You need to search an element in above array in o(log n) time complexity.
<b>Solution </b>: <a href="http://www.java2blog.com/search-element-in-sorted-and-rotated-array-java.html" target="_blank" rel="noopener noreferrer">Search element in rotated and sorted array</a>

<hr />

<h4 style="text-align: left;">Question 19 : Find minimum element in a sorted and rotated array.</h4>
You are given an sorted and rotated array as below:
<pre name="code" class="">int arr[]={16,19,21,25,3,5,8,10};
Minimum element in the array : 3
</pre>
If you note that array is sorted and rotated. You need to i an element in above array in o(log n) time complexity.
<b>Solution </b>: <a href="https://java2blog.com/find-minimum-element-in-sorted-and-rotated-array-java/" target="_blank" rel="noopener noreferrer">Find minimum element in a sorted and rotated array</a>

<hr />

<h4 style="text-align: left;">Question 20: Find second largest number in an array</h4>
<div style="font-size: medium; font-weight: normal;">You are given an sorted and rotated array as below:</div>
<div style="font-size: medium; font-weight: normal;"><b>For example:</b></div>
<pre name="code" style="font-weight: normal;" class="">int[] arr1={7,5,6,1,4,2};
Second largest element in the array : 6</pre>
<div style="text-align: left;"><b>Solution : </b><a href="http://www.java2blog.com/find-second-largest-number-in-array-java.html" target="_blank" rel="noopener noreferrer">java program to find second largest number in an array</a>.</div>
<div>

<hr />

<h4 style="text-align: left;">Question 21 : Find the number occurring odd number of times in an array</h4>
<div style="font-size: medium; font-weight: normal;">You are given a array of integer. All numbers occur even number of times except one. You need to find the number which occurs odd number of time. You need to solve it with o(n) time complexity and o(1) space complexity.
For example:
<pre name="code" style="text-align: left;">int array[] = new int[]{20, 40, 50, 40, 50, 20, 30, 30, 50, 20, 40, 40, 20};
Number which occurs odd number of times is : 50</pre>
</div>
<div style="text-align: left;"><b>Solution : </b><a href="http://www.java2blog.com/find-number-occurring-odd-number-of-times-in-array.html" target="_blank" rel="noopener noreferrer">java program to find number occurring odd number of times in an array</a>.</div>
</div>

<hr />

<h4 style="text-align: left;">Question 22 : Find minimum number of platforms required for railway station</h4>
<span style="font-weight: normal;">You are given arrival and departure time of trains reaching to a particular station. You need to find minimum number of platforms required to accommodate the trains at any point of time.</span>
<div style="font-size: medium; font-weight: normal;">

<b>For example:</b>
<pre name="code">arrival[] = {1:00, 1:40, 1:50, 2:00, 2:15, 4:00} 
departure[] = {1:10, 3:00, 2:20, 2:30, 3:15, 6:00}
No. of platforms required in above scenario = 4</pre>
Please note that arrival time is in chronological order.

</div>
<div style="font-size: medium; font-weight: normal;"><b>Solution : </b><a href="http://www.java2blog.com/minimum-number-of-platforms-required-for-railway-station.html" target="_blank" rel="noopener noreferrer">Find minimum number of platforms required for railway station</a>.</div>

<hr />

<h4 style="text-align: left;">Question 23 : Find a Pair Whose Sum is Closest to zero in Array</h4>
<div style="font-weight: normal;">Given array of +ve and -ve integers ,we need to find a pair whose sum is closed to Zero in Array.</div>
<div style="font-weight: normal;"><b>For example:</b></div>
<pre name="code" style="font-weight: normal;">array[]={1,3,-5,7,8,20,-40,6};
The pair whose sum is closest to zero :  -5 and 6</pre>
<div style="font-size: medium; font-weight: normal;"><b>Solution : </b><a href="http://www.java2blog.com/find-pair-whose-sum-is-closest-to-zero-in-array.html" target="_blank" rel="noopener noreferrer">Find a Pair Whose Sum is Closest to zero in Array in java</a>.</div>

<hr />

<h4 style="text-align: left;">Question 24 : Given a sorted array and a number x, find the pair in array whose sum is closest to x</h4>
<div style="font-weight: normal;">
<div>Given a sorted array, we need to find a pair whose sum is closed to number X in Array.</div>
<div><b>For example:</b></div>
<pre name="code" class="">array[]={-40,-5,1,3,6,7,8,20};
The pair whose sum is closest to 5 :  1 and 3</pre>
</div>
<div style="font-size: medium; font-weight: normal;"><b>Solution : </b><a href="http://www.java2blog.com/given-sorted-array-number-x-find-pair-closest-to-x-array.html" target="_blank" rel="noopener noreferrer">Find a Pair Whose Sum is Closest to X in Array in java</a>.</div>

<hr />

<h4 style="text-align: left;">Question 25 : Find all pairs of elements from an array whose sum is equal to given number</h4>
<div style="font-weight: normal;">
<div>Given a  array,we need to find all pairs whose sum is equal to number X.</div>
<div><b>For example:</b></div>
<pre name="code" class="">array[]={ -40, -5, 1, 3, 6, 7, 8, 20 };
Pair of elements whose sum is equal to 15 :  7, 8 and -5, 20</pre>
</div>
<div style="font-size: medium; font-weight: normal;"><b>Solution : </b><a href="http://www.java2blog.com/find-all-pairs-elements-from-array-sum-equals-given-number-java.html" target="_blank" rel="noopener noreferrer">Find all pairs of elements from an array whose sum is equal to given number </a>.</div>
<div>

<hr />

<h4 style="text-align: left;">Question 26: Given an array of 0’s and 1’s in random order, you need to separate 0’s and 1’s in an array.</h4>
<div style="font-weight: normal;">
<div><b>For example:</b></div>
<pre name="code" class="">arr[] = {0,1,0,0,1,1,1,0,1}
Array after separating 0 and 1 numbers :
{0,0,0,0,1,1,1,1,1}</pre>
</div>
<div style="font-size: medium; font-weight: normal;"><b>Solution : </b><a href="https://java2blog.com/separate-0s-and-1s-in-array/" target="_blank" rel="noopener">Separate 0s and 1s in array</a>.</div>
</div>
</div>

<hr />

<h4 style="text-align: left;">Question 27 : Separate odd and even numbers in an array</h4>
Given an array of integers, you need to segregate odd and even numbers in an array.
Please note: Order of elements can be changed.
<div style="font-weight: normal;">
<div><b>For example:</b></div>
<pre name="code" class="">arr[] = {12, 17, 70, 15, 22, 65, 21, 90}
Array after separating odd and even numbers :
{12, 90, 70, 22, 15, 65, 21, 17}</pre>
</div>
<div style="font-size: medium; font-weight: normal;"><b>Solution : </b><a href="https://java2blog.com/separate-odd-and-even-numbers-in-array/" target="_blank" rel="noopener">Separate 0s and 1s in array</a>.</div>
</div>
<div dir="ltr" style="text-align: left;">
<div>

<hr />

<h4 style="text-align: left;">Question 28 : Given an array containing zeroes, ones and twos only. Write a function to sort the given array in O(n) time complexity.</h4>
<div style="font-weight: normal;">
<div><b>For example:</b></div>
<pre name="code" class="">Input :
[1, 2, 2, 0, 0, 1, 2, 2, 1]
 
Output :
[0, 0, 1, 1, 1, 2, 2, 2, 2]
</pre>
</div>
<div style="font-size: medium; font-weight: normal;"><b>Solution : </b><a href="https://java2blog.com/sort-array-of-0s-1s-and-2s/" target="_blank" rel="noopener">Sort an array of 0s, 1s and 2s</a>.</div>

<hr />

<h4 style="text-align: left;">Question 29 : Find local minima in array</h4>
A local minima is less than its neighbours
<div style="font-weight: normal;">
<div><b>For example:</b></div>
<pre name="code" class="">Input :

int [] arr = {10, 5, 3, 6, 13, 16, 7};
Output: 2
 
int []arr = {11,12,13,14};
Output: 11
 
int []arr = {10};
Output: 10
 
int []arr = {8,6};
Output: 6
</pre>
</div>

<hr />

<h4 style="text-align: left;">Question 30 : Sliding window maximum in java</h4>
Given an Array of integers and an Integer k, Find the maximum element of from all the contiguous subarrays of size K.
<div style="font-weight: normal;">
<div><b>For example:</b></div>
<pre name="code" class="">Input :
Input : int[] arr = {2,6,-1,2,4,1,-6,5}
int k = 3
output : 6,6,4,4,4,5
</pre>
</div>
<div style="font-size: medium; font-weight: normal;"><b>Solution : </b><a href="https://java2blog.com/sliding-window-maximum-java/" target="_blank" rel="noopener">Find the local minima in array</a>.</div>

<hr />

<h4 style="text-align: left;">Question 31 : Count number of occurrences (or frequency) of each element in a sorted array</h4>
Given a Sorted Array of integers containing duplicates. Find the frequency of every unique element present in the array.
Frequency is defined as the number of occurrence of any element in the array.

<b>For example :</b>
<pre name="code" class="">Input :
Input:
int[] arr = {1, 1, 1, 3, 3, 4, 5, 5, 6, 6};
Output:
Frequency of 1 is : 3
Frequency of 3 is : 2
Frequency of 4 is : 1
Frequency of 5 is : 2
Frequency of 6 is : 2
</pre>
</div>
<div style="font-size: medium; font-weight: normal;"><b>Solution : </b><a href="https://java2blog.com/count-occurences-frequency-each-element-sorted-array/" target="_blank" rel="noopener">Count number of occurrences (or frequency) of each element in a sorted array</a>.</div>

<hr />

<h4 style="text-align: left;">Question 32 : Find subarrays with given sum in an array.</h4>
Given an Array of non negative Integers and a number. You need to print all the starting and ending indices of Subarrays having their sum equal to the given integer.
<b>For example :</b>
<pre name="code" class="">Input :
Input-int[] arr = {2, 3, 6, 4, 9, 0, 11};
int num = 9
Output-
starting index : 1, Ending index : 2
starting index : 5, Ending index : 5
starting index : 5, Ending index : 6
</pre>
</div>
<div style="font-size: medium; font-weight: normal;"><b>Solution : </b><a href="https://java2blog.com/find-subarrays-given-sum-array/" target="_blank" rel="noopener">Find subarrays with given sum in an array</a>.</div>

<hr />

<h4>Question 33 : Find peak element in the array.</h4>
Peak Element is the element of the array which is GREATER THAN / EQUAL TO its neighbours, that is, for an element at i th index, the neighbour elements at index i-1 &amp; i+1 must be greater than equal to element at i th position.
<div style="font-size: medium; font-weight: normal;"><b>Solution : </b><a href="https://java2blog.com/find-subarrays-given-sum-array/" target="_blank" rel="noopener">Find peak element in the array</a>.</div>

<hr />

<h4>Question 34 : Find leaders in an array.</h4>
We need to print all the leaders present in the array. Element is the leader if it is greater than right side of elements.
<pre>arr[]={14, 12, 70, 15, 99, 65, 21, 90}
Here 99 and 90 are leader elements
</pre>
<b>For example:</b>
<div style="font-size: medium; font-weight: normal;"><b>Solution : </b><a href="https://java2blog.com/find-leaders-in-array/" target="_blank" rel="noopener">Find leaders in an array</a>.</div>

<hr />

<h4 style="text-align: left;">Question 35 : Count 1’s in sorted Binary Array.</h4>
Print number of 1’s in a given sorted Binary Array.
<b>For example :</b>
<pre name="code" class="">Input :
int[] arr = {0,0,0,1,1,1,1};
output : 4
int[] arr = {0,0,1};
output : 1
</pre>
<div style="font-size: medium; font-weight: normal;"><b>Solution : </b><a href="https://java2blog.com/count-1s-sorted-binary-array/" target="_blank" rel="noopener">Count 1’s in sorted Binary Array</a>.</div>

<hr />

<h4 style="text-align: left;">Question 36 : Find first repeating element in an array of integers.</h4>
Find the first repeating element in array of integers.
<b>For example :</b>
<pre name="code" class="">Input :
Input: array[] = {10, 7, 8, 1, 8, 7, 6}
Output: 7 [7 is the first element actually repeats]
</pre>
<div style="font-size: medium; font-weight: normal;"><b>Solution : </b><a href="https://java2blog.com/find-first-repeating-element-array-integers/" target="_blank" rel="noopener">Find first repeating element in an array of integers</a>.</div>

<hr />

<h4 style="text-align: left;">Question 37 : Check if Array Elements are Consecutive.</h4>
Given an array, we need to check if array contains consecutive elements.
<b>For example :</b>
<pre name="code" class="">Input: array[] = {5, 3, 4, 1, 2}
Output: true
As array contains consecutive elements from 1 to 5Input: array[] = {47, 43, 45, 44, 46}
Output: true
As array contains consecutive elements from 43 to 47Input: array[] = {6, 7, 5, 6}
Output: false
As array does not contain consecutive elements.
</pre>
<div style="font-size: medium; font-weight: normal;"><b>Solution : </b><a href="https://java2blog.com/check-array-elements-consecutive/" target="_blank" rel="noopener">Check if Array Elements are Consecutive</a>.</div>

<hr />

<h4 style="text-align: left;">Question 38 : Permutations of array in java.</h4>
Given array of distinct integers, print all permutations of the array.
<b>For example :</b>
<pre name="code" class="">array : [10, 20, 30]

Permuations are :

[10, 20, 30]
[10, 30, 20]
[20, 10, 30]
[20, 30, 10]
[30, 10, 20]
[30, 20, 10]
</pre>
<div style="font-size: medium; font-weight: normal;"><b>Solution : </b><a href="https://java2blog.com/permutations-array-java/" target="_blank" rel="noopener">Permutations of array in java</a>.</div>

<hr />

<h4 style="text-align: left;">Question 39 : Rotate an array by K positions.</h4>
<b>For example :</b>
<pre name="code" class="">N=6 and k=2
If Arr[] = {1, 2, 3, 4, 5, 6} and k=2
then rotated array will be  {5, 6, 1, 2,  3,  4}
</pre>
<div style="font-size: medium; font-weight: normal;"><b>Solution : </b><a href="https://java2blog.com/rotate-array-by-k-positions/" target="_blank" rel="noopener">Rotate an array by K positions</a>.</div>

<hr />

<h4 style="text-align: left;">Question 40 : Stock Buy Sell to Maximize Profit.</h4>
Given an array of integers representing stock price on single day, find max profit that can be earned by 1 transaction.
So you need to find pair (buyDay,sellDay) where buyDay &lt; = sellDay and it should maximise the profit.
<b>For example :</b>
<pre name="code" class="">int arr[]={14, 12, 70, 15, 99, 65, 21, 90};
Max profit can be gain by buying at 1th day(0 based indexing) and sell at 4th day.
Max profit = 99-12 =87
</pre>
<div style="font-size: medium; font-weight: normal;"><b>Solution : </b><a href="https://java2blog.com/stock-buy-sell-to-maximize-profit/" target="_blank" rel="noopener">Stock Buy Sell to Maximize Profit</a>.</div>

<hr />

<h4 style="text-align: left;">Question 41 : Find maximum difference between two elements such that larger element appears after the smaller number.</h4>
Given array of integers, find Maximum difference between two elements such that larger element appears after the smaller number
<b>For example :</b>
<pre name="code" class="">int arr[]={14, 12, 70, 15, 95, 65, 22, 30};
Max Difference =95-12 = 83
</pre>
<div style="font-size: medium; font-weight: normal;"><b>Solution : </b><a href="https://java2blog.com/maximum-difference-between-two-elements-in-array/" target="_blank" rel="noopener">Maximum difference between two elements such that larger element appears after the smaller number</a>.</div>

<hr />

<h4 style="text-align: left;">Question 42 : Search in a row wise and column wise sorted matrix.</h4>
Given row wise and column wise sorted matrix ,we need to search element with minimum time complexity.
<div style="font-size: medium; font-weight: normal;"><b>Solution : </b><a href="https://java2blog.com/search-in-row-wise-and-column-wise-sorted-matrix/" target="_blank" rel="noopener">Search in a row wise and column wise sorted matrix</a>.</div>

<hr />

<h4 style="text-align: left;">Question 43 : Largest sum contiguous subarray.</h4>
Largest sum contiguous subarray is the task of finding the contiguous subarray within a one-dimensional array of numbers which has the largest sum.
<b>For example :</b>
<pre name="code" class="">for the sequence of values −2, 1, −3, 4, −1, 2, 1, −5, 4; the contiguous subarray with the largest sum is 4, −1, 2, 1, with sum 6
</pre>
<div style="font-size: medium; font-weight: normal;"><b>Solution : </b><a href="https://java2blog.com/largest-sum-contiguous-subarray/" target="_blank" rel="noopener">Largest sum contiguous subarray</a>.</div>

<hr />

<h4 style="text-align: left;">Question 44 : Find the Contiguous Subarray with Sum to a Given Value in an array.</h4>
Given an array of positive integer and given value X, find Contiguous sub array whose sum is equal to X.
<b>For example :</b>
<pre name="code" class="">arr[]={14, 12, 70, 15, 99, 65, 21, 90}; 
X =97.
Sum found between index 1 to 3
Elements are 12, 17 and 15
</pre>
<div style="font-size: medium; font-weight: normal;"><b>Solution : </b><a href="https://java2blog.com/find-contiguous-subarray-with-sum-to-given-value-array/" target="_blank" rel="noopener">Find the Contiguous Subarray with Sum to a Given Value in an array</a>.</div>

<hr />

<h4 style="text-align: left;">Question 45 : Longest Common Prefix in an array of Strings in java.</h4>
Given an array of positive integer and given value X, find Contiguous sub array whose sum is equal to X.
<b>For example :</b>
<pre name="code" class="">String[] strArr={"java2blog","javaworld","javabean","javatemp"};
So Longest common prefix in above String array will be “java” as all above string starts with “java”.
</pre>
<div style="font-size: medium; font-weight: normal;"><b>Solution : </b><a href="https://java2blog.com/longest-common-prefix-in-array-of-strings-java/" target="_blank" rel="noopener">Longest Common Prefix in an array of Strings in java</a>.</div>
<div>
<h4 style="text-align: left;">Question 46 : Find all subsets of set (power set) in java.</h4>
Given a set of distinct integers, arr, return all possible subsets (the power set).
<b>For example :</b>
<pre name="code" class="">Input: nums = [1,2,3]
Output:
[
[3],
[1],
[2],
[1,2,3],
[1,3],
[2,3],
[1,2],
[]
]
</pre>
<div style="font-size: medium; font-weight: normal;"><b>Solution : </b><a href="https://java2blog.com/longest-common-prefix-in-array-of-strings-java/" target="_blank" rel="noopener">Find all subsets of set in java</a>.</div>
</div>
<h2><span style="color: #800000;">String</span></h2>

<hr />

<h4 style="text-align: left;">Question 47 : How to reverse a String in java? Can you write a program without using any java inbuilt methods?</h4>
<div>
<div dir="ltr">

<b>Solution:</b> There are many ways to do it, some of them are:
<ul style="text-align: left;">
 	<li>Using for loop</li>
 	<li>Using recursion</li>
 	<li>Using StringBuffer</li>
</ul>
<div>Please refer to the solution at <a href="http://www.java2blog.com/java-program-to-reverse-string.html" target="_blank" rel="noopener">reverse a String in java</a></div>
</div>
</div>
<div>

<hr />

<h4 style="text-align: left;">Question 48 : Write a java program to check if two Strings are anagram in java?</h4>
</div>
<div>

<strong>Solution: </strong>Two string are anagrams if they have same characters but in different order. For example: Angel and Angle are anagrams
There are few ways to check if Strings are anagrams. Some of them are:
<ol>
 	<li>Using String methods</li>
 	<li>Using array.sort</li>
</ol>
<div>Check solution at <a href="http://www.java2blog.com/check-if-two-strings-are-anagrams-in-java-example-program.html">check if two Strings are anagram in java.</a></div>

<hr />

<h4 style="text-align: left;">Question 49 : Write a program to check if String has all unique characters in java?</h4>
<strong>Solution: </strong>Here are some ways to check if String contains all unique characters

</div>
<div>
<ul style="text-align: left;">
 	<li>By using HashSet</li>
 	<li>Using indexOf and lastIndexOf methods of String</li>
 	<li>By Using ascii value of characters.</li>
</ul>
<div>Please refer to complete solution at <a href="http://www.java2blog.com/check-if-string-has-all-unique-characters-in-java.html" target="_blank" rel="noopener">check if String has all unique characters</a>.</div>
</div>
<div>

<hr />

<h4 style="text-align: left;">Question 50 : How to check if one String is rotation of another String in java?</h4>
<strong>Solution: Let's</strong> say you want to check whether str1 and str2 is rotation of one another or not.
<ol>
 	<li>Create a new String with str3= str1 + str1</li>
 	<li>Check if str3 <a href="http://www.java2blog.com/2016/05/java-string-contains-example.html" target="_blank" rel="noopener">contains</a> str2 or not.</li>
 	<li>if str3 <a href="http://www.java2blog.com/2016/05/java-string-contains-example.html" target="_blank" rel="noopener">contains</a> str2 then str2 is rotation of str1 else it is not</li>
</ol>
<div>You can find complete solution at <a href="http://www.java2blog.com/check-if-one-string-is-rotation-of-another-java.html" target="_blank" rel="noopener">check if one String is rotation of another in java</a>.</div>
</div>
<div>

<hr />

<h4 style="text-align: left;">Question 51 : How to find duplicate characters in String in java?</h4>
<strong>Solution:  </strong>Here is a solution to find duplicate characters in String.
<ol>
 	<li>Create a <a href="http://www.java2blog.com/hashmap-in-java-with-examples.html" target="_blank" rel="noopener">HashMap</a> and character of String will be inserted as key and its count as value.</li>
 	<li>If <a href="http://www.java2blog.com/hashmap-in-java-with-examples.html" target="_blank" rel="noopener">Hashamap</a> already contains char,increase its count by 1, else put char in HashMap.</li>
 	<li>If value of Char is more than 1, that means it is duplicate character in that String.</li>
</ol>
<div style="text-align: left;"><span style="font-weight: normal;">Please refer to solution at<a href="http://www.java2blog.com/2016/05/find-duplicate-characters-in-string-java.html" target="_blank" rel="noopener"> program to find duplicate characters in a String</a>.</span></div>
</div>
<div>

<hr />

<h4 style="text-align: left;">Question 52 : Find first non repeated character in String in java?</h4>
<strong>Solution: </strong>There are may ways to find it.
Some of them are:
<ul style="text-align: left;">
 	<li>Using <a href="https://java2blog.com/linkedhashmap-in-java-with-example/">LinkedHashMap</a></li>
 	<li>Using indexOf and lastIndexOf methods.</li>
</ul>
<div>Please find complete solution at <a href="http://www.java2blog.com/find-first-non-repeated-character-in.html" target="_blank" rel="noopener">find first non repeated character in  a String</a>.</div>
</div>
<div>

<hr />

<h4 style="text-align: left;">Question 53 : Find all substrings of String in java?</h4>
<div dir="ltr"><strong>Solution:</strong> Java program to find all <a href="https://java2blog.com/find-all-substrings-of-string-in-java/">substrings</a> of a String.
For example: If input is "abb"  then output should be "a", "b","b", "ab", "bb", "abb"</div>
<div dir="ltr">We will use String class's subString method to find all subString.
Please refer to complete solution at <a href="http://www.java2blog.com/2015/08/find-all-substrings-of-string-in-java.html" target="_blank" rel="noopener">find all subStrings of String.</a></div>
</div>
<div>

<hr />

<h4 style="text-align: left;">Question 54 : Find length of String without using any inbuilt method in java?</h4>
<strong>Solution:</strong> You can use try catch block for catching StringIndexOutOfBoundException and when this exception aries, you can simply return i(Index at which you will get the exception)
Please refer to complete solution at <a href="http://www.java2blog.com/find-length-of-string-without-using.html" target="_blank" rel="noopener">find length of String without inbuilt methods</a>.

</div>
<div>

<hr />

<h4 style="text-align: left;">Question 55 : Write a program to print all permutations of String in java?</h4>
</div>
<strong>Solution:</strong> Take out first character of String and insert into different places of permutations of remaining String recursively. Please find complete solution at <a href="http://www.java2blog.com/find-all-permutations-of-string-in-java.html">how to find all permutations of String in java</a>.
<div>
<h2><span style="color: #800000;">Binary Tree</span></h2>

<hr />

<h4 style="text-align: left;">Question 56 : How can you traverse binary tree?</h4>
There are three ways to traverse binary tree.
<ul style="text-align: left;">
 	<li><a href="http://www.java2blog.com/binary-tree-preorder-traversal-in-java.html" target="_blank" rel="noopener noreferrer">PreOrder</a></li>
 	<li><a href="http://www.java2blog.com/binary-tree-inorder-traversal-in-java.html" target="_blank" rel="noopener noreferrer">InOrder</a></li>
 	<li><a href="http://www.java2blog.com/binary-tree-postorder-traversal-in-java.html" target="_blank" rel="noopener noreferrer">PostOrder</a>.</li>
</ul>
<div>

<hr />

<h4 style="text-align: left;">Question 57 : Write an algorithm to do level order traversal of binary tree?</h4>
</div>
<div>You need to write java program to do level order traversal of binary tree. You can use queue data structure to do level order traversal.</div>
<div style="clear: both; text-align: center;"></div>
<div style="clear: both; text-align: center;"><a style="margin-left: 1em; margin-right: 1em;" href="https://4.bp.blogspot.com/-9ZfyN1HIsU4/U8pBOBFEVBI/AAAAAAAADQU/hzEVUv0l_qg70nnqRlCyQWqaFTvuJaFMgCPcB/s1600/LevelOrderTraversal.jpg"><img src="https://4.bp.blogspot.com/-9ZfyN1HIsU4/U8pBOBFEVBI/AAAAAAAADQU/hzEVUv0l_qg70nnqRlCyQWqaFTvuJaFMgCPcB/s400/LevelOrderTraversal.jpg" width="400" height="279" border="0" /></a></div>
<div>
<div style="text-align: left;"></div>
<div style="text-align: left;"><b>Solution </b>: <a href="http://www.java2blog.com/binary-tree-level-order-traversal-in.html" target="_blank" rel="noopener noreferrer">Level order traversal of binary tree.</a></div>

<hr />

<h4 style="text-align: left;">Question 58 :  Write an algorithm to do spiral order traversal of binary tree?</h4>
</div>
<div>You need to write java program to do spiral level order traversal of binary tree</div>
<div style="clear: both; text-align: center;"><a style="margin-left: 1em; margin-right: 1em;" href="https://2.bp.blogspot.com/-ngOLkuERRkE/U9B9A6wKGGI/AAAAAAAADRo/PeIrrdiac-YJTRBsU57hnq8VYPIxS6IXQCPcB/s1600/SpiralTraversalOfBinaryTree.jpg"><img src="https://2.bp.blogspot.com/-ngOLkuERRkE/U9B9A6wKGGI/AAAAAAAADRo/PeIrrdiac-YJTRBsU57hnq8VYPIxS6IXQCPcB/s400/SpiralTraversalOfBinaryTree.jpg" width="400" height="267" border="0" /></a></div>
<div>

<b>Solution </b>: <a href="http://www.java2blog.com/spiralzigzag-level-order-traversal-of.html" target="_blank" rel="noopener noreferrer">Sprial order or zigzag traversal of binary tree.</a>

<hr />

<h4 style="text-align: left;">Question 59 : How can you print leaf nodes of binary tree?</h4>
</div>
<div>You need to write java program to print all leaf nodes of binary tree.</div>
<div style="clear: both; text-align: center;"><a style="margin-left: 1em; margin-right: 1em;" href="https://2.bp.blogspot.com/-PYnM66CqEHU/U8pr_oueEQI/AAAAAAAADQw/ZcOIEJaLK8QFvYnigQPnOzpxeastoJ_wgCPcB/s1600/updatedBinaryTree.jpg"><img src="https://2.bp.blogspot.com/-PYnM66CqEHU/U8pr_oueEQI/AAAAAAAADQw/ZcOIEJaLK8QFvYnigQPnOzpxeastoJ_wgCPcB/s320/updatedBinaryTree.jpg" width="320" height="221" border="0" /></a></div>
Leaf nodes for above binary tree will be 5 , 30 , 55 ,70
<b>Solution </b>:<a href="http://www.java2blog.com/how-to-print-leaf-nodes-of-binary-tree.html" target="_blank" rel="noopener noreferrer"> Print leaf nodes of binary tree.</a>

<hr />

<h4 style="text-align: left;">Question 60 : How to count leaf nodes of binary tree.</h4>
You need to write java program to count leaf nodes of binary tree.
Count of Leaf nodes for binary tree used in Question 15 are <b>5</b>.
<b>Solution </b>: <a href="http://www.java2blog.com/program-to-count-leaf-nodes-in-binary.html" target="_blank" rel="noopener noreferrer">Count leaf nodes of binary tree.</a>

<hr />

<h4 style="text-align: left;">Question 61 : How to print all paths from root to leaf in binary tree.</h4>
You need to write a program to print all paths from root to leaf.
<div style="clear: both; text-align: center;"><a style="margin-left: 1em; margin-right: 1em;" href="https://3.bp.blogspot.com/-Wt5jULjXxHA/U90abF_QhlI/AAAAAAAADS4/RYdIEhU_WponN6jy2MbgoFeUBKNcnsRQwCPcB/s1600/printPathsToRootToLeafInBinaryTree.jpg"><img src="https://3.bp.blogspot.com/-Wt5jULjXxHA/U90abF_QhlI/AAAAAAAADS4/RYdIEhU_WponN6jy2MbgoFeUBKNcnsRQwCPcB/s400/printPathsToRootToLeafInBinaryTree.jpg" width="400" height="290" border="0" /></a></div>
<b>Solution </b>: <a href="http://www.java2blog.com/print-all-paths-from-root-to-leaf-in.html" target="_blank" rel="noopener noreferrer">Print all paths from root to leaf in binary tree.</a>

<hr />

<h4 style="text-align: left;">Question 62 : How to find level of node in binary tree</h4>
Given a node, you need to find level of a node. For example : Level of node will 3 for node 70 used in Question 14.
<b>Solution</b>: <a href="http://www.java2blog.com/get-level-of-node-in-binary-tree-in-java.html" target="_blank" rel="noopener noreferrer">Find level of node in binary tree.</a>

<hr />

<h4 style="text-align: left;">Question 63 : How to find maximum element in binary tree.</h4>
You need to write a java program to find maximum element in binary tree.
<b>Solution </b>: <a href="https://java2blog.com/find-maximum-element-binary-tree-java/" target="_blank" rel="noopener noreferrer">Find maximum element in binary tree.</a>

<hr />

<h4 style="text-align: left;">Question 64 : How to find lowest common ancestor(LCA) in binary tree.</h4>
You need to write a program to find LCA in binary tree.
<div style="clear: both; text-align: center;"></div>
<div style="clear: both; text-align: center;"><a style="margin-left: 1em; margin-right: 1em;" href="https://3.bp.blogspot.com/-_gLipfU6NNs/Vw9BZZCQAAI/AAAAAAAAEdQ/YnmE_P_ff18tnZ8_4zO3KeMBhumpNWGCgCPcB/s1600/LCA.png"><img src="https://3.bp.blogspot.com/-_gLipfU6NNs/Vw9BZZCQAAI/AAAAAAAAEdQ/YnmE_P_ff18tnZ8_4zO3KeMBhumpNWGCgCPcB/s400/LCA.png" width="400" height="282" border="0" /></a></div>
<b>Solution</b>: <a href="http://www.java2blog.com/lowest-common-ancestor-of-binary-tree.html" target="_blank" rel="noopener noreferrer">Program to find LCA in binary tree.</a>

<hr />

<h4 style="text-align: left;">Question 65 : How to do boundary traversal of binary tree.</h4>
Write a java program to do boundary traversal of binary tree as shown in below image.
<div style="clear: both; text-align: center;"><a style="margin-left: 1em; margin-right: 1em;" href="https://3.bp.blogspot.com/-zdIDNbOoJRI/Vw6RKLnFplI/AAAAAAAAEcQ/5IRJuqrNmDE8MIDmxNp2he4cE05QP5BNwCPcB/s1600/BoundaryTraversal.png"><img src="https://3.bp.blogspot.com/-zdIDNbOoJRI/Vw6RKLnFplI/AAAAAAAAEcQ/5IRJuqrNmDE8MIDmxNp2he4cE05QP5BNwCPcB/s400/BoundaryTraversal.png" width="400" height="312" border="0" /></a></div>
Solution : <a href="http://www.java2blog.com/boundary-traversal-of-binary-tree-in.html" target="_blank" rel="noopener noreferrer">Boundary traversal of binary tree.</a>

<hr />

<h4 style="text-align: left;">Question 66 : How to print vertical sum of binary tree?</h4>
You need to find sum of nodes which lies in same column.
<div style="clear: both; text-align: center;"><a href="https://2.bp.blogspot.com/-gFPNh_dhSSI/Vjz4_mGN2YI/AAAAAAAAEIQ/GAL1gwuyiGAuIADiaBEp0LfAV03o5d_2ACPcB/s1600/verticalSum.jpg.png"><img src="https://2.bp.blogspot.com/-gFPNh_dhSSI/Vjz4_mGN2YI/AAAAAAAAEIQ/GAL1gwuyiGAuIADiaBEp0LfAV03o5d_2ACPcB/s400/verticalSum.jpg.png" width="400" height="333" border="0" /></a></div>
Solution : <a href="http://www.java2blog.com/vertical-sum-of-binary-tree-in-java.html" target="_blank" rel="noopener noreferrer">How to print vertical sum of binary tree</a>.

<hr />

<h4 style="text-align: left;">Question 67 : Count subtrees with Sum equal to target in binary tree?</h4>
Given a <a href="https://java2blog.com/binary-tree-in-java/" target="_blank" rel="noopener">Binary tree</a> and an integer. You need to find the number of subtrees having the sum of all of its nodes equal to given Integer, that is, Target sum.

Solution : <a href="http://www.java2blog.com/vertical-sum-of-binary-tree-in-java.html" target="_blank" rel="noopener noreferrer">Count subtrees with Sum equal to target in binary tree</a>.
<h2><span style="color: #800000;">Binary Search tree</span></h2>

<hr />

<h4 style="text-align: left;">Question 68 : What is binary search tree?</h4>
Binary search tree is a special type of <a href="http://www.java2blog.com/binary-tree-in-java.html" target="_blank" rel="noopener noreferrer">binary tree</a> which have following properties.
<ul style="text-align: left;">
 	<li>Nodes which are smaller than root will be in left subtree.</li>
 	<li>Nodes which are greater than root will be right subtree.</li>
 	<li>It should not have duplicate nodes</li>
 	<li>Both left and right subtree also should be binary search tree.</li>
</ul>

<hr />

<h4 style="text-align: left;">Question 69 : Can you write algorithm to insert a node in binary search tree.</h4>
</div>
<div><b>Solution </b>: <a href="https://java2blog.com/binary-search-tree-in-java/" target="_blank" rel="noopener noreferrer">Insert node in binary search tree</a></div>

<hr />

<h4 style="text-align: left;">Question 70 : Can you write algorithm to delete a node in binary search tree.</h4>
<div><b>Solution </b>: <a href="https://java2blog.com/how-to-delete-node-from-binary-search-tree-java/" target="_blank" rel="noopener noreferrer">Delete node in binary search tree</a></div>

<hr />

<h4 style="text-align: left;">Question 71 :  How can you find minimum and maximum elements in binary search tree?</h4>
<div><b>Solution </b>: Leftmost and rightmost nodes of binary search tree are minimum and maximum nodes respectively</div>
<div><a href="https://java2blog.com/find-minimum-and-maximum-elements-binary-search-tree-java/" target="_blank" rel="noopener noreferrer">Minimum and maximum elements in binary search tree</a>.</div>
<div>

<hr />

<h4 style="text-align: left;">Question 72 : How to find lowest common ancestor(LCA) in binary search tree.</h4>
You need to write a program to find LCA in binary search tree.
<div style="clear: both; text-align: center;"></div>
<div style="clear: both; text-align: center;"><a style="margin-left: 1em; margin-right: 1em;" href="https://3.bp.blogspot.com/-_gLipfU6NNs/Vw9BZZCQAAI/AAAAAAAAEdQ/YnmE_P_ff18tnZ8_4zO3KeMBhumpNWGCgCPcB/s1600/LCA.png"><img src="https://3.bp.blogspot.com/-_gLipfU6NNs/Vw9BZZCQAAI/AAAAAAAAEdQ/YnmE_P_ff18tnZ8_4zO3KeMBhumpNWGCgCPcB/s400/LCA.png" width="400" height="282" border="0" /></a></div>
<b>Solution</b>: <a href="http://www.java2blog.com/lowest-common-ancestor-of-binary-search.html" target="_blank" rel="noopener noreferrer">Program to find LCA in binary search tree.</a>

</div>
<div>

<hr />

<h4 style="text-align: left;">Question 73 : Find inorder successor in a Binary search Tree</h4>
You need to write a program to find inorder successor in a Binary search tree.

<b>Solution</b>: <a href="https://java2blog.com/inorder-successor-binary-search-tree/" target="_blank" rel="noopener">Inorder Successor in a Binary Search Tree</a>

<hr />

<h4 style="text-align: left;">Question 74 : Convert sorted array to balanced BST</h4>
<b>Solution</b>: <a href="https://java2blog.com/convert-sorted-array-to-balanced-binary-search-tree/" target="_blank" rel="noopener">Convert sorted sorted array to balanced BST</a>

<hr />

<h4 style="text-align: left;">Question 75 : Convert sorted Linked List to balanced BST</h4>
<b>Solution</b>: <a href="https://java2blog.com/convert-sorted-linkedlist-to-balanced-bst/" target="_blank" rel="noopener">Convert sorted Linked List to balanced BST</a>

<hr />

<h4 style="text-align: left;">Question 76 : Check if a binary tree is binary search tree or not in java</h4>
<b>Solution</b>: <a href="https://java2blog.com/check-if-binary-tree-is-binary-search-tree-java/" target="_blank" rel="noopener">Check if a binary tree is binary search tree or not in java</a>
<h2><span style="color: #800000;">Sorting</span></h2>
</div>
<div>

<hr />

<h4 style="text-align: left;">Question 77 : Write an algorithm to implement bubble sort?</h4>
</div>
<div><b>Solution </b>: <a href="https://java2blog.com/implement-bubble-sort-in-java/" target="_blank" rel="noopener noreferrer">Bubble sort in java</a></div>
<div>

<hr />

<h4 style="text-align: left;">Question 78 : Write an algorithm to implement insertion sort sort?</h4>
</div>
<div><b>Solution </b>: <a href="https://java2blog.com/implement-insertion-sort-in-java/" target="_blank" rel="noopener noreferrer">Insertion sort in java</a></div>
<div>

<hr />

<h4 style="text-align: left;">Question 79 : Write an algorithm to implement selection sort sort?</h4>
</div>
<div><b>Solution </b>: <a href="https://java2blog.com/selection-sort-in-java/" target="_blank" rel="noopener noreferrer">Selection sort in java</a></div>

<hr />

<h4 style="text-align: left;">Question 80 : Can you write algorithm for merge sort and also do you know complexity of merge sort?</h4>
<div><b>Solution </b>: <a href="https://java2blog.com/implement-merge-sort-in-java/" target="_blank" rel="noopener noreferrer">Merge sort in java</a></div>
<div>

<hr />

<h4 style="text-align: left;">Question 81 : Do you know how to implement Heap sort?</h4>
</div>
<div><b>Solution </b>: <a href="https://java2blog.com/heap-sort-in-java/" target="_blank" rel="noopener noreferrer">implement Heap sort in java</a></div>

<hr />

<h4 style="text-align: left;">Question 82 : Implement quick sort in java?</h4>
<div><b>Solution </b>: <a href="https://java2blog.com/quick-sort-in-java/" target="_blank" rel="noopener noreferrer">implement Quick sort in java</a></div>

<hr />

<h4 style="text-align: left;">Question 83 : Implement shell sort in java?</h4>
<div><b>Solution </b>: <a href="https://java2blog.com/shell-sort-in-java/" target="_blank" rel="noopener noreferrer">implement Shell sort in java</a></div>

<hr />

<h4 style="text-align: left;">Question 84 : Implement Counting sort in java?</h4>
<div><b>Solution </b>: <a href="https://java2blog.com/counting-sort-in-java/" target="_blank" rel="noopener noreferrer">implement Counting sort in java</a></div>
<div>

<hr />

<h4 style="text-align: left;">Question 85 : What is binary search? Can you write an algorithm to find an element in sorted array using binary search?</h4>
</div>
<div><b>Solution </b>:<a href="https://java2blog.com/binary-search-java/" target="_blank" rel="noopener noreferrer">Binary search algorithm in java</a></div>
<div>
<h2><span style="color: #800000;">Graph</span></h2>

<hr />

<h4 style="text-align: left;">Question 86 : Write algorithm to do depth first search in a graph.</h4>
<div><b>Solution </b>: <a href="http://www.java2blog.com/depth-first-search-in-java.html" target="_blank" rel="noopener noreferrer">Depth first search in java</a></div>
<div>

<hr />

<h4 style="text-align: left;">Question 87 : Write algorithm to do breadth first search in a graph.</h4>
<div>Solution : <a href="http://www.java2blog.com/breadth-first-search-in-java.html" target="_blank" rel="noopener noreferrer">breadth first search in java</a></div>
</div>

<hr />

<h4 style="text-align: left;">Question 88 : Explain Dijkstra algorithm from source to all other vertices.</h4>
<img class="aligncenter size-full wp-image-4477" src="https://java2blog.com/wp-content/uploads/2017/11/DijkstraInitialize.png" alt="DijkstraInitialize" width="700" height="470" />
<div>Solution : <a href="https://java2blog.com/dijkstra-java/" target="_blank" rel="noopener noreferrer">Dijkstra’s algorithm in java</a></div>

<hr />

<h4 style="text-align: left;">Question 89 : Explain Bellman Ford algorithm to find shortest distance</h4>
<img class="aligncenter size-full wp-image-6895" src="https://java2blog.com/wp-content/uploads/2018/11/bellman-Ford1.jpg" alt="Bellman Ford" width="301" height="321" />
<div>Solution : <a href="https://java2blog.com/bellman-ford-algorithm-java/" target="_blank" rel="noopener noreferrer">Bellman ford algorithm in java</a></div>

<hr />

<h4 style="text-align: left;">Question 90 : Explain Kruskal's algorithm for finding minimum spanning tree</h4>
<img class="aligncenter size-full wp-image-7013" src="https://java2blog.com/wp-content/uploads/2018/12/Kruskals1.png" alt="Kruskals1" width="366" height="210" />
<div>Solution : <a href="https://java2blog.com/kruskals-algorithm-minimum-spanning-tree/" target="_blank" rel="noopener noreferrer">Kruskal's algorithm</a></div>
<h2><span style="color: #800000;">Dynamic Programming</span></h2>

<hr />

<h4 style="text-align: left;">Question 91 : Given two String, find longest common substring.</h4>
Solution: <a href="https://java2blog.com/longest-common-substring-java/" target="_blank" rel="noopener">Longest common substring in java</a>.

<hr />

<h4 style="text-align: left;">Question 92 : Given two Strings A and B. Find the length of the Longest Common Subsequence (LCS) of the given Strings.</h4>
Solution: <a href="https://java2blog.com/longest-common-subsequence-java/" target="_blank" rel="noopener">Longest common subsequence in java</a>

<hr />

<h4 style="text-align: left;">Question 93 : Given a matrix, we need to count all paths from top left to bottom right of MxN matrix. You can either move down or right.</h4>
<img class="aligncenter size-full wp-image-6359" src="https://java2blog.com/wp-content/uploads/2018/08/MatrixPaths.jpg" alt="Matrix paths" width="271" height="280" />

Solution: <a href="https://java2blog.com/count-paths-top-left-bottom-right-mxn-matrix/" target="_blank" rel="noopener">Count all paths in matrix</a>

<hr />

<h4 class="title single-title entry-title">Question 94 : Edit Distance Problem in java</h4>
Given two strings string1 and string2, String1 is to be converted into String2 with the given operations available in the minimum number of steps. Using any one of the given operations contributes to the increment of steps by one.

Allowed Operations are :
(i) <strong>Remove</strong> : This operation allows the Removal any one character from String.
(ii) <strong>Insert</strong> : This operation allows the Insertion of one character at any spot in the String.
(iii) <strong>Replace</strong> : This operation allows the replacement of any one character in the string with
any other character.

Solution: <a href="https://java2blog.com/edit-distance-problem/" target="_blank" rel="noopener">Edit distance problem in java</a>.

<hr />

<h4 class="title single-title entry-title">Question 95: Coin change problem in java</h4>
Given an Amount to be paid and the currencies to pay with. There is infinite supply of every currency using combination of which, the given amount is to be paid. Print the number of ways by which the amount can be paid.

Solution: <a href="https://java2blog.com/coin-change-problem-java/" target="_blank" rel="noopener">Coin change problem in java</a>

<hr />

<h4 class="title single-title entry-title">Question 96 : Minimum number of jumps to reach last index</h4>
Solution: <a href="https://java2blog.com/minimum-number-jumps-reach-last-index/">Minimum number of jumps to reach last index</a>.
<h2><span style="color: #800000;">Miscellaneous</span></h2>

<hr />

<h4 style="text-align: left;">Question 97 : What is an algorithm and how to calculate complexity of algorithms.</h4>
Solution : <a href="http://www.java2blog.com/introduction-to-complexity-of-algorithm.html" target="_blank" rel="noopener noreferrer">How to calculate Complexity of algorithm</a>

<hr />

<h4 style="text-align: left;">Question 98 : Implement trie data structure in java.</h4>
<img class="aligncenter size-full wp-image-4004" src="https://4.bp.blogspot.com/-GNWc5KUMGYc/WAskP-EHFKI/AAAAAAAAEz4/8yikxc2niYgyqH0FWFafq5UTp_kUK6O5ACLcB/s1600/TrieDataStructureImpl.png" alt="Stack" width="530" height="396" />
Solution : <a href="https://java2blog.com/trie-data-structure-in-java/" target="_blank" rel="noopener noreferrer">Implement trie data structure in java.</a>

<hr />

<h4 style="text-align: left;">Question 99 : Count Factorial Trailing Zeroes in java.</h4>
Solution : <a href="https://java2blog.com/count-factorial-trailing-zeroes-java/" target="_blank" rel="noopener noreferrer">Count Factorial Trailing Zeroes in java</a>

<hr />

<h4 style="text-align: left;">Question 100 : Largest Rectangular Area in a Histogram.</h4>
Solution : <a href="https://java2blog.com/largest-rectangular-area-histogram/" target="_blank" rel="noopener noreferrer">Count Largest Rectangular Area in a Histogram</a>

<hr />

<h4 style="text-align: left;">Question 101 : Check for balanced parentheses in an expression in java.</h4>
Solution : <a href="https://java2blog.com/check-for-balanced-parentheses-in-expression-java/" target="_blank" rel="noopener noreferrer">check for balanced parentheses in an expression in java.</a>

<hr />

<h4 style="text-align: left;">Question 102 : What is Memoization.</h4>
Solution :
Memoization ensures that method does not execute more than once for same inputs by storing the results in the data structure(Usually Hashtable or HashMap or Array).
<a href="https://java2blog.com/memoization-example-java/" target="_blank" rel="noopener noreferrer">Memoization example in java</a>
Source:<a href="https://java2blog.com/data-structure-and-algorithm-interview-questions-in-java/" target="_blank" rel="noopener noreferrer">data structure and algorithm interview questions in java</a>

This is all about questions on data structure and algorithm interview questions. Please do comment if you want to add any new questions to above list.
You may also like:
<ul>
 	<li><a href="http://www.java2blog.com/core-java-interview-questions-and-answers.html" target="_blank" rel="noopener noreferrer">Core java interview questions</a></li>
 	<li><a href="http://www.java2blog.com/java-collections-interview-questions.html" target="_blank" rel="noopener noreferrer">Java Collections interview questions</a></li>
 	<li><a href="http://www.java2blog.com/java-string-interview-questions-and-answers.html" target="_blank" rel="noopener noreferrer">Java String interview questions</a></li>
 	<li><a href="http://www.java2blog.com/oops-interview-questions-answers-java.html" target="_blank" rel="noopener noreferrer">OOPs interview questions in java</a></li>
 	<li><a href="http://www.java2blog.com/java-multithreading-interview-questions-and-answers.html" target="_blank" rel="noopener noreferrer">Java Multithreading interview questions</a></li>
 	<li><a href="http://www.java2blog.com/java-exception-handling-interview-questions-and-answers.html" target="_blank" rel="noopener noreferrer">Exceptional handling interview questions in java</a></li>
 	<li><a href="http://www.java2blog.com/java-serialization-interview-questions-and-answers.html" target="_blank" rel="noopener noreferrer">Java Serialization interview questions in java</a></li>
 	<li><a href="http://www.java2blog.com/web-services-interview-questions.html" target="_blank" rel="noopener noreferrer">web services interview questions</a></li>
 	<li><a href="http://www.java2blog.com/restful-web-services-interview-questions.html" target="_blank" rel="noopener noreferrer">restful web services interview questions</a></li>
 	<li><a href="http://www.java2blog.com/spring-interview-questions-and-answers.html" target="_blank" rel="noopener noreferrer">Spring interview questions</a></li>
<li><a href="https://java2blog.com/spring-boot-interview-questions/" target="_blank" rel="noopener noreferrer">Spring boot interview questions</a></li>
 	<li><a href="http://www.java2blog.com/hibernate-interview-questions-and-answers.html" target="_blank" rel="noopener noreferrer">Hibernate interview questions</a></li>
</ul>
</div>

</div>