Skip to main content

Arrays in Java


  1) Find a Missing number in an integer array of 1 to 100

This class finds the missing number from an array It uses two approaches

a)Using sum of first n numbers which is n(n+1)/2, and
  subtract each of the array elements from the sum, which
  gives the missing number.

b) Using XOR, Which finds the XOR of all numbers in the
   given array, and also the XOR of first n numbers the XOR for these two calculations will give the    missing number




2)  Find 2 Missing Numbers from an Array

This class finds two missing numbers from an Array

It uses the XOR approach to find the results, and uses the three step approach

First will do the XOR to find the missing number(which could be  the sum of the two numbers, says 3 and 5 are missing from the Array,We get 8, as the Array is sorted 8 can not be the sum of 4 and 4. So 8 has to be the sum of one number less than 4(half of it) and one number more than it.



  3) Find First Non-Repeating elements in an array of Integers.



  4) Compare two integer arrays efficiently


  5) Sort Elements in an Array using Various Sorting Techniques


  6) How do You find duplicate number on Integer array in Java


  7) Find smallest and Largest numbers in an Integer Array


  8) Find repeated numbers in an array, if it contains multiple duplicates


  9) Remove duplicates from an array


  10) Find intersection of two sorted arrays in Java


  11) Find Kth Smallest element in unsorted Array


  12) Find Kth Largest element in unsorted Array


  13) Find first repeating elements in an array of Integers



  14) Check if an array contains  numbers in java(if it contains string and integer)


  15) Top 2 numbers form an integer array


  16) Remove a given element from an array


  17) Remove duplicates from an array


  18) Merge 2 integer arrays

19) Find PeakElement of An Array



20) Find Fixed Point or Magic Index of an Array



21) Replace Every Element in the Array with the Greatest element to it's Right.



 22) Find Odd Number of times Occurring Element in an Array


 23) Find Majority Element in an Array



 24) Find Leader Elements in an Array



 25)  Reverse an array in-place



Comments

Popular posts from this blog

HashMap in Java

1) Implement HashMap in Java, with the put and get operations   HashMap can be implemented in Java Using Arrays. Use the same logic that the Out of the Box   HashMap follows, for resizing, and load factor, when ever the HashMap reaches the size of the   resize with the load factor a new Array is created, and the previous array contents are copied over   to the new Array.  HashMap is Not Synchronized by default. We can synchronize the whole map by using Synchronization, or by using collection.synchronizedmap(map), which synchronizes all the operations on the map. Alternatively We can use the CocurrentHashMap which does not lock the read operations, rather locks the segments that are being written. 2) HashMap vs LinkedHashMap vs IdentityHashMap 3) HashMap vs ConcurrentHashMap 4) Implement a Cache using LinkedHashMap