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

Design Patterns using Java

According to Gang of Four(GOF) any software is classified in to one of the three categories. I read so many books about design patterns which provide a lot of information about Design Patterns in a language neutral way or related to a particular programming language. I am trying to complement the great books by providing the precise and concise information that is required in the day to day programming of a Java Developer. Any software can be classified into one of the three categories -Framework, Toolkit, Application. Framework - Framework defines a set of steps to create an application. Framework provides design reuse. Toolkit - Toolkit provides some utility functions to an existing application. Toolkit provides code reuse. Application - Application is some thing that is specific to the project, and is not useful outside the context of the current application. Gang of Four divided the Design Patterns in to 3 types based on their usage. There are 3 types of Gang of Fo