## Find Intersection of Two Arrays – Java Code

Given two sorted arrays, Write a java code to find intersection of two arrays.

For example, if the input arrays are:

arr1[] = {2, 3, 6, 7, 9, 11}
arr2[] = {4, 6, 8, 9, 12}

Then your program should print intersection as {6, 9}. Before writing actual code, let’s first discuss different approaches to solve this problem.

## Find Next Greater Element in an Array – Java Code

Write a java program to find next greater element in an array. Given an input array, find the next greater element for every element of an array.The next greater element x is the first greater element on the right side of x in an array.

For example:

Let’s take an array: [4, 2, 6, 8, 1]

4 => 6 (First next greater element of 4 is 6)
2 => 6 (Next greater element of 2 is 6)
6 => 8 (Next greater element of 6 is 8)
8 => null
1 => null

## Java program to check anagram : Check whether Two Strings are Anagrams of each other

Write a java program to check anagram. In this programming question, we are going to write a java code to check whether two strings are anagrams of each other.

Let’s first understand what is an anagram? and how we are going to solve this problem.

## What is an Anagram?

Two strings are said to be anagrams of each other if it contains the same characters, only the order of characters in both the strings is different. In other words, both strings must contain the same exact letters in the same exact frequency.

## Generate Prime Numbers between 1 to N – Sieve of Eratosthenes

Write an efficient program to generate prime numbers between 1 to N (Where N is 10, 100, 1000 etc). This question can also be asked like this, Generate prime numbers between 1 to 100 or 1 to 10 etc.

Suppose the value of N is 10, So the prime numbers between 1 to 10 is 2, 3, 5, 7.  Now let’s learn the most efficient algorithm (Sieve of Eratosthenes) to generate Prime Numbers between 1 to N. Before solving this program, let’s understand what is a prime number.

## MySql Query to Find Second Highest Salary

Write a MySql query to find second highest salary. This question is mostly asked in interviews and it’s also a bit tricky. In this tutorial, You are going to learn three easiest ways to write a MySql query to find second highest salary.

## Program to print triangle pattern of numbers and stars (*)

Write a program to print triangle pattern of numbers and stars (*). In this program i’ll show how to create triangle pattern of numbers , stars (*) . These type of questions are very important in terms of interviews as well.

## MCQ on Recursion

Recursion is the most important concept in computer science. In my previous posts, i have written about binary search implementation using recursion and difference between recursion and iteration.

These MCQ helps you to understand the concept of Recursion.

1) Which Data Structure is used to perform Recursion?

a) Queue
b) Stack