Array Questions

Searching Searching an element in an unsorted arraySearching an element in a sorted array Sorting Sort an arraySort list of words in lexicographical orderMerge two sorted array Other Union of…

Implement Stack using Array

Program to implemnet stack using array public class StackImpWithArray { static final int MAX=2; int top; int bucket[]=new int[MAX]; StackImpWithArray(){ top=-1; } boolean push(int val){ if(top<MAX-1){ top++; bucket[top]=val; System.out.println("Value Pushed");…

Minimum and Maximum Element in an Array

package arrays; import java.util.Arrays; public class MinAndMaxInArray { public static void main(String[] args) { System.out.println(Arrays.toString(returnMinMax(new int[]{}))); System.out.println(Arrays.toString(returnMinMax(new int[]{1, 2, 3, 4, 5, 6}))); System.out.println(Arrays.toString(returnMinMax(new int[]{1, 2,-2,34,53,-2,0}))); } /** * Reversing…

Trailing zeroes in Factorial of a Number

Given a no find no of trailing zeroes present in the factorial of that number public class TrailingZeroes { public static void main(String[] args) { System.out.println(trailingZeroesInFactorial(10)); System.out.println(trailingZeroesInFactorial(45)); System.out.println(trailingZeroesInFactorial(50)); } static…

Valid Parenthesis

Check if teh given set of parenthesis are valid import java.util.HashMap; import java.util.Map; import java.util.Stack; public class ValidParentheses { public static void main(String[] args) { System.out.println(isValid("()[]{}")); } static boolean isValid(String…

Sort Array with 0, 1 and 2s

Given an array containing elements in form of 0, 1, and 2 sort the array import java.util.Arrays; public class SortArrayWithZeroesOnesAndTwos { public static void main(String[] args) { System.out.println(Arrays.toString(getSortedArray(new int[]{2,1,0,0,1,2,0,2,1}))); }…