Algorithm
10 OctoberConvert sorted array to balanced binary search tree
If you want to practice data structure and algorithm programs, you can go through 100+ java coding interview questions. In this post , we will see how to convert sorted array to balanced binary search tree. Algorithm: You might know that inorder traversal of binary search tree results in sorted array. We will use this property […]
06 OctoberMaximum difference between two elements such that larger element appears after the smaller number
If you want to practice data structure and algorithm programs, you can go through 100+ java coding interview questions. Given array of integers, find Maximum difference between two elements such that larger element appears after the smaller number For example: [crayon-6ab5e223caf39256536665/] Algorithm: Lets say we have array arr[] of stock prices. We will track two variable :minElementTillNow and maxDifference. minElementTillNow will be […]
03 OctoberStock Buy Sell to Maximize Profit
If you want to practice data structure and algorithm programs, you can go through 100+ java coding interview questions. Given an array of integers representing stock price on a single day, find max profit that can be earned by 1 transaction. So you need to find a pair (buyDay,sellDay) where buyDay < = sellDay and it […]
23 SeptemberSort a Stack using another stack
If you want to practice data structure and algorithm programs, you can go through 100+ java coding interview questions. In this post, we will see how to sort a stack using another stack. Problem Given a Stack, you need to sort it with the help of temporary stack. Solution : Let’s say, you have two stacks, […]
16 SeptemberCheck if a binary tree is binary search tree or not in java
If you want to practice data structure and algorithm programs, you can go through 100+ java coding interview questions. In this post, we will see how to check if given binary tree is binary search tree or not. This is one of important interview questions on binary tree. We will see two approaches to check if […]
16 SeptemberStack implementation in java
If you want to practice data structure and algorithm programs, you can go through 100+ java coding interview questions. In this post, we will see how to implement Stack using Array in java. Introduction Stack is abstract data type which demonstrates Last in first out (LIFO) behavior. We will implement same behavior using Array. Although java […]
15 SeptemberCheck for balanced parentheses in an expression in java
If you want to practice data structure and algorithm programs, you can go through Java coding interview questions. In this post, we will see how to check for balanced parentheses in an expression. Lets say, you have expression as a*(b+c)-(d*e) If you notice, above expression have balanced parentheses. Lets take another expression as (a*(b-c)*(d+e) If you observe, […]
10 SeptemberImplement Stack using two Queues in java
If you want to practice data structure and algorithm programs, you can go through 100+ java coding interview questions. In this program, we will see how to implement stack using Linked List in java. Stack is abstract data type which demonstrates Last in first out (LIFO) behavior. We will implement same behavior using two queue. There […]
10 SeptemberImplement stack using Linked List in java
If you want to practice data structure and algorithm programs, you can go through 100+ java coding interview questions. In this program, we will see how to implement stack using Linked List in java. The Stack is an abstract data type that demonstrates Last in first out (LIFO) behavior. We will implement the same behavior using […]