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.

Move All Zeroes to the End of Array – Java Code

In this tutorial, We are going to discuss another interesting problem to move all zeroes to end of array. Given an array of random integers move all zeroes of a given array to then end of an array. The order of all other elements of an array should be same.

For example, if a given array is {1, 2, 0, 4, 0, 5, 3, 8}, than the output should be {1, 2, 4, 5, 3, 8, 0, 0}.

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 Find Missing Number in Array

Write a java program to find missing number in array. Given an array of n-1 integers and these integers are in the range of 1 to n. One of the integer is missing from an array. We have to write an efficient java code to find missing number from an array. An array does not contains any duplicates.

Find GCD of Two Numbers using Recursion – Java Code

Write a Java program to find GCD of two numbers using Recursion. Given two input integers, we have to write a code to find GCD of two numbers using recursion. For this program, I assume you are familiar with the concept of recursion. If you don’t know about recursion then check my previous post on recursion vs iteration.