Reverse an integer array in java using iterative & recursive algorithm

Given an integer array in java. Reverse input array using iterative & recursive algorithm. Example to reverse an integer array using java Let input array is { 1, 2, 3, 4, 5 } Reverse input array is {5, 4, 3, 2, 1} Algorithm: reverse an integer array using iterative algorithm Initialize length = inputArray.length & half =… Read More »

Find intersection/common elements of two sorted integer arrays in java (example)

Given two sorted arrays containing distinct elements. We would like to find out the intersection of two sorted arrays. Intersection is nothing but the common elements of two sorted arrays. 1. Examples: intersection or common elements of two sorted arrays in java Example #1: Given X= { 1, 2, 3, 4 } &  Y = {3, 4,… Read More »

Replace every element in integer array by greatest number on its right (java/ example)

Given an array of integers in java. Replace every element of array with greatest number on its right. The right most element will always replaced by -1. 1. Examples: replace every elements by maximum number on its right (java) 1.1 Example #1: Given an integer array { 4, 10, 7, 5 } Find out the… Read More »

Find leader elements/numbers in integer array (java/example/iterative algorithm)

Given an integer array in java, find out the leader elements in an array. What is leader element in an array? The element which is greater than the elements to its right. The element on the extreme right, is assumed to be the leader element. 1. Examples: leader elements/ numbers in integer array (java/ example)… Read More »