## Check for Balanced Parentheses in an Expression using Stack – Java Code

Write a java code to check for balanced parentheses in an expression using stack. Given an expression containing characters ‘{‘,’}’,'(‘,’)’,'[‘,’]’. We have to write a code to check whether an input string has valid parentheses.

An input string is valid if:

Open brackets must be closed by the same type of brackets.
Open brackets must be closed in the correct order.

Example –

i) {[]}) – Invalid
ii) {()}[] – Valid

## Find Duplicate Characters in a String : Java Code

Given an input string, Write a java code to find duplicate characters in a String. In this tutorial, I am going to explain multiple approaches to find duplicate characters in a string.

For example :

Subscribe Our Tutorials

Get Latest Updates on Facebook

Input string: “Java”
Duplicate character : a

Input string: “programming”
Duplicate character : m,g,r

## Queue using Two Stacks – Java Code & Algorithm

How to implement a queue using two stacks. In this tutorial, We are going to discuss an algorithm and java code to implement a queue using two stacks.

## Find Common Elements in Three Sorted Arrays – Java Code

Write a java program to find common elements in three sorted arrays. Given three sorted arrays, write a code to print intersection of three sorted arrays.

For example –

arr1 = {1, 5, 10, 20, 40, 80};
arr2 = {6, 7, 20, 80, 100};
arr3 = {3, 4, 15, 20, 30, 70, 80, 120};

Output : {20, 80}

20 and 80 is the common element between three sorted arrays.

## Get Minimum Element from Stack in O(1)

Design a stack to get minimum element from stack in O(1) (constant time).

For example : Suppose, If we push following elements in a stack.

9  ==> Top
1
2
3

Then if we call getMin() method, It should return 1 in O(1) (constant time). In a stack, Element which pushed last in the stack is the first element to be popped out. Think for a moment how we can solve this problem.