Netxd Software India Interview Questions – 2

This blog explains about  Netxd Software India  Interview Questions and is given below

 NETXD SOFTWARE INDIA  PVT. LTD

1. Pattern Program:

public class Pattern1  

{  

public static void main(String args[])   

{   

int i, j,number, n=7;   

for(i=0; i<n; i++)  

{   

number=1;     

for(j=0; j<=i; j++)  

{    

System.out.print(number+ ” “);     

number++;   

}    

System.out.println();   

}   

}   

Output:

1

1 2

1 2 3

1 2 3 4

1 2 3 4 5

1 2 3 4 5 6

1 2 3 4 5 6 7

2. Print non repeated element in array

Given an array A[] consisting of N (1 ? N ? 105) positive integers, the task is to find the only array element with a single occurrence.

Note: It is guaranteed that only one such element exists in the array.

ex:

Input: A[] = {1, 1, 2, 3, 3}
Output: 2

Explanation:
Distinct array elements are {1, 2, 3}.
Frequency of these elements are {2, 1, 2} respectively.

Input : A[] = {1, 1, 1, 2, 2, 3, 5, 3, 4, 4}
Output : 5

 Follow the steps below to solve the problem

public class Main {

    public static void CalcUnique (int[] arr, int N)
{

            Arrays.sort(arr);

        int temp=Integer.MIN_VALUE;

        int count=0;

           for(int i=0;i<N;i++){

            if(arr[i]==temp){

                count++;

            }
else
{

                if(count==1)
{

                    System.out.println(temp);

                    return;

                }

                temp=arr[i];

                count=1;

            }

        }

             System.out.println(arr[N-1]);

        }

        publicstaticvoidmain(String[] args) {

        int[] arr = {1, 1, 2, 3, 3};

        intN = arr.length;

        CalcUnique(arr, N);

    }

}
OUTPUT:
2

3. Check Subset of Array:-

Check One Array is Subset of Another Array in Java.

In Java, Array is an object. It is a non-primitive data type which stores values of similar data type.

As per the problem statement we have to check whether one array is subset of another array. An array is a subset of another array if all the elements of subarray is present in the given array.

  • Step 1 − Declare and initialize an integer array.
  • Step 2 − Implement the logic for multiple approaches.
  • Step 3 − initialise two for loops and check if elements of inner for loop matches outer for loop.
  • Step 4 − Print the result.

public class Main
{
public static void main(String args[])
{
int array1[] = { 33, 51, 5, 31, 9, 4, 3 };
int array2[] = { 51, 9, 33, 3 };
int x = array1.length;
int y = array2.length;
subset(array1, array2, x, y);
if (subset(array1, array2, x, y))
{
System.out.print(“array 2 is a subset of array 1”);
}
else
{
System.out.print(“array 2 is not a subset of array 1”);
}
}
//user defined method to check if array 2 is present in array 1
static boolean subset (int array1[], int array2[], int x, int y)
{
int i, j = 0;
for (i = 0; i < y; i++)
{
for (j = 0; j < x; j++)
if (array2[i] == array1[j])
break;
/* return false when arr2[i] is not present in arr1[] */
if (j == x)
return false;
}
/* return true when all elements of arr2[] are present in arr1[] */
return true;
}
}

OUTPUT:-
array 2 is a subset of array 1

Courtesy:-

https://www.javatpoint.com/

https://www.tutorialspoint.com/