Sunday, November 25, 2018

1-D Array Interview questions in JAVA

--------------
ARRAYS :
------------
How to find the missing number in integer array of 1 to 100?

How to find duplicate number on Integer array in Java?
Solution :
public class MyClass {
    public static void main(String args[]) {
        int no[]={10,20,10,30,40,50,40,60,78,100};
        for(int i=0;i<no.length;i++)
        {
            for(int j=i+1;j<no.length;j++)
                if(no[i]==no[j])
                {
                    System.out.println(no[i]+" is duplicate");
                    break;
                }
         }
      }
}

How to find largest and smallest number in unsorted array?

How to find all pairs on integer array whose sum is equal to given number?

Write a program to remove duplicates from array in Java?

There is an array with every element repeated twice except one. Find that element? (solution)
This is an interesting array coding problem, just opposite of question related to finding duplicates in array. Here you need to find the unique number which is not repeated twice. For example if given array is {1, 1, 2, 2, 3, 4, 4, 5, 5} then your program should return 3. Also, don't forget to write couple of unit test for your solution.

How to find common elements in three sorted array? (solution)
Now we are coming on territory of tough array questions. Given three arrays sorted in non-decreasing order, print all common elements in these arrays.

Examples:
input1 = {1, 5, 10, 20, 40, 80}
input2 = {6, 7, 20, 80, 100}
input3 = {3, 4, 15, 20, 30, 70, 80, 120}
Output: 20, 80

How to remove duplicates from array in place?


How to reverse array in place in Java

How to check if array contains a duplicate

No comments:

Post a Comment