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]

Subscribe Our Tutorials

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 Reverse a String using Recursion

Write a java program to reverse a string using recursion. In this tutorial, I am going to explain how to write a java code which reverse an input string using recursion. I have also added the video at the end of this tutorial.

For example :

Input String: Object
Output String: tcejbO

Anagram Program in Java : Check whether Two Strings are Anagrams of each other

Write a anagram program in java or 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.

Prime Number Program in C

Write a prime number program in C. In this tutorial, we are going to write a c program to check whether a number is prime or not. Given an integer, We have to write an efficient code to check whether a number is prime or not.

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.

Find Second Highest Salary in MySql

Write a query to find second highest salary inMySql . This question is mostly asked in an interviews and it’s also a bit tricky. In this tutorial, We 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