Wipro Assessment Questions With Solution Part - 2

LOGIC 1:
FIND FIRST REPEATED ELEMENT IN THE GIVEN ARRAY FROM THE FIRST
INDEX:
Rajeev works in the data center lab of the survey department. He has been
assigned the task of identifying “repeated numbers” in a given set of numbers.
He approaches you to help him achieve this.
Given an array of numbers, your task is to return the first repeated number in
the array starting from the first index.
For example – if input1={1,2,4,1,2,8} representing the given array, and
input2=6 representing the number of elements in array, then the result should
be 1 which is the first repeated number in the array.
Special conditions should be taken care:
Note 1: You should ignore the negative numbers and zeros. The program
consider only non-zero, non-negative numbers from the given array.
Note 2: If no number is repeated then the output should be the first element
of the array.
Note 3: If all elements in the array are negative or 0’s the output should be 0.
PROGRAM:
package digpgm;
import java.util.*;
public class dipgm {
public static void main(String[] args) {
Scanner sc=new

Scanner(System.in);

int n=sc.nextInt();
int a[]=new int[n];
int count=0,i,g=0;
for( i=0;i<a.length;i++){
a[i]=sc.nextInt();
//System.out.println(a[i]);
}
for(i=0;i<a.length;i++){

if(a[i]<0 || a[i]==0){
count++;
}

}

if(count==n){
System.out.println("0");
}
for(i=0;i<a.length;i++){
for(int j=i+1;j<a.length;j++){
if(a[i]==a[j] && a[i]>0){

System.out.println(a[i]);
g++;
System.exit(0);
}
/*else if(a[i]!=a[j]){

System.out.println(a[0]);

break aa;*/
}

}
for(i=0;i<a.length;i++)
{
if(g==0 && count<n && a[i]>0)
{
System.out.println(a[i]);
System.exit(0);
}
}
}
}

LOGIC 2:
FIND FIRST REPEATED ELEMENT IN THE GIVEN ARRAY FROM THE FIRST
INDEX:
Rajeev works in the data center lab of the survey department. He has been
assigned the task of identifying “repeated numbers” in a given set of numbers.
He approaches you to help him achieve this.
Given an array of numbers, your task is to return the first repeated number in
the array starting from the first index.

For example – if input1={1,2,4,1,2,8} representing the given array, and
input2=6 representing the number of elements in array, then the result should
be 1 which is the first repeated number in the array.
Special conditions should be taken care:
Note 1: You should ignore the zeros. The program consider only non-zero from
the given array.
Note 2: If no number is repeated then the output should be the first element
of the array.
Note 3: If all elements in the array are 0’s the output should be 0.
PROGRAM:
package pattern;
import java.util.*;
public class Ex3 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);

int n=sc.nextInt();
int a[]=new int[n];
int count=0,i,g=0;
for( i=0;i<a.length;i++){
a[i]=sc.nextInt();
//System.out.println(a[i]);
}
aa:for(i=0;i<a.length;i++){
for(int j=i+1;j<a.length;j++){
if(a[i]==a[j]){
System.out.println(a[i]);
g++;
System.exit(0);
}
/*else if(a[i]!=a[j]){
System.out.println(a[0]);
break aa;*/
}

}
for(i=0;i<a.length;i++)
{
if(g==0 || a[i]==0)

{
System.out.println(a[i]);
System.exit(0);
}
}
}
}

LOGIC 3:
FIND FIRST REPEATED ELEMENT IN THE GIVEN ARRAY FROM THE FIRST
INDEX:
Rajeev works in the data center lab of the survey department. He has been
assigned the task of identifying “repeated numbers” in a given set of numbers.
He approaches you to help him achieve this.
Given an array of numbers, your task is to return the first repeated number in
the array starting from the first index.
For example – if input1={1,2,4,1,2,8} representing the given array, and
input2=6 representing the number of elements in array, then the result should
be 1 which is the first repeated number in the array.
Special conditions should be taken care:
Note 1: You should ignore the negative numbers. The program consider only
zero and non-zero, from the given array.
Note 2: If no number is repeated then the output should be the last element of
the array.
Note 3: If all elements in the array are negative the output should be last
element of the array.
PROGRAM:
package pattern;
import java.util.*;
public class Ex3 {

public static void main(String[] args) {
Scanner sc=new Scanner(System.in);

int n=sc.nextInt();
int a[]=new int[n];
int count=0,i,g=0;
for( i=0;i<a.length;i++){
a[i]=sc.nextInt();
//System.out.println(a[i]);
}
for(i=0;i<a.length;i++){
if(a[i]<0){
count++;
}
}
if(count==n){
System.out.println(a[a.length-1]);
}
aa:for(i=0;i<a.length;i++){
for(int j=i+1;j<a.length;j++){
if(a[i]==a[j] &&a[i]>=0){
System.out.println(a[i]);
g++;
System.exit(0);
}
/*else if(a[i]!=a[j]){
System.out.println(a[0]);
break aa;*/
}

}
for(i=0;i<a.length-1;i++)
{
if(g==0 && a[i]>0)
{
System.out.println(a[a.length-1]);
System.exit(0);
}
}
}
}

LOGIC 4:
FIND FIRST REPEATED ELEMENT IN THE GIVEN ARRAY FROM THE FIRST
INDEX:
Rajeev works in the data center lab of the survey department. He has been
assigned the task of identifying “repeated numbers” in a given set of numbers.
He approaches you to help him achieve this.
Given an array of numbers, your task is to return the first repeated number in
the array starting from the first index.
For example – if input1={1,2,4,1,2,8} representing the given array, and
input2=6 representing the number of elements in array, then the result should
be 1 which is the first repeated number in the array.
Special conditions should be taken care:
Note 1: The program consider all the numbers from the given array.
Note 2: If no number is repeated then the output should be the first element
of the array.
Note 3: If all elements in the array are negative or 0’s the output should be 0.
PROGRAM:
package pattern;
import java.util.*;
public class Ex3 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);

int n=sc.nextInt();
int a[]=new int[n];
int count=0,i,g=0;
for( i=0;i<a.length;i++){
a[i]=sc.nextInt();
//System.out.println(a[i]);
}
ab:for(i=0;i<a.length;i++){
if(a[i]<0){
count++;
}
}

if(count==n){
System.out.println("0");
}
aa:for(i=0;i<a.length;i++){
for(int j=i+1;j<a.length;j++){
if(a[i]==a[j]){
System.out.println(a[i]);
g++;
System.exit(0);
}
/*else if(a[i]!=a[j]){
System.out.println(a[0]);
break aa;*/
}

}
ab:for(i=0;i<a.length-1;i++)
{
if(g==0 && count<n || a[i]>0)
{
System.out.println(a[i]);
break ab;
}
}
}
}

LOGIC 5:
FIND FIRST REPEATED ELEMENT IN THE GIVEN ARRAY FROM THE FIRST
INDEX:
Rajeev works in the data center lab of the survey department. He has been
assigned the task of identifying “repeated numbers” in a given set of numbers.
He approaches you to help him achieve this.

Given an array of numbers, your task is to return the first repeated number in
the array starting from the first index.
For example – if input1={1,2,4,1,2,8} representing the given array, and
input2=6 representing the number of elements in array, then the result should
be 1 which is the first repeated number in the array. SUM = 9.
Special conditions should be taken care:
Note 1: You should ignore the negative numbers and zeros. The program
consider only non-zero, non-negative numbers from the given array.
Note 2: If no number is repeated then the output should be the first element
of the array.
Note 3: If all elements in the array are negative or 0’s the output should be 0.
Note 4: Finally sum of the first and last element from the array.
PROGRAM:
package pattern;
import java.util.*;
public class Ex3 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);

int n=sc.nextInt();
int a[]=new int[n];
int count=0,i,g=0;
for( i=0;i<a.length;i++){
a[i]=sc.nextInt();
//System.out.println(a[i]);
}
ab:for(i=0;i<a.length;i++){
if(a[i]<0){
count++;
}
}
if(count==n){
System.out.println("0");
System.out.println(a[0]+a[a.length-1]);
}

aa:for(i=0;i<a.length;i++){
for(int j=i+1;j<a.length;j++){
if(a[i]==a[j] && a[i]>0){
System.out.println(a[i]);
System.out.println(a[0]+a[a.length-1]);
g++;
System.exit(0);
}
/*else if(a[i]!=a[j]){
System.out.println(a[0]);
break aa;*/
}

}
ab:for(i=0;i<a.length-1;i++)
{
if(g==0 && count<n || a[i]>0)
{
System.out.println(a[i]);
System.out.println(a[0]+a[a.length-1]);
break ab;
}
}
}
}

LOGIC 6:
FIND FIRST REPEATED ELEMENT IN THE GIVEN ARRAY FROM THE FIRST
INDEX:
Rajeev works in the data center lab of the survey department. He has been
assigned the task of identifying “repeated numbers” in a given set of numbers.
He approaches you to help him achieve this.
Given an array of numbers, your task is to return the first repeated number in
the array starting from the first index.

For example – if input1={1,2,4,1,2,8} representing the given array, and
input2=6 representing the number of elements in array, then the result should
be 1 which is the first repeated number in the array. SUM=18
Special conditions should be taken care:
Note 1: You should ignore the negative numbers and zeros. The program
consider only non-zero, non-negative numbers from the given array.
Note 2: If no number is repeated then the output should be the first element
of the array.
Note 3: If all elements in the array are negative or 0’s the output should be 0.
Note 4: Finally 2*( sum of the first and last element from the array).
PROGRAM:
package pattern;
import java.util.*;
public class Ex3 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);

int n=sc.nextInt();
int a[]=new int[n];
int sum=0;
int count=0,i,g=0;
for( i=0;i<a.length;i++){
a[i]=sc.nextInt();
//System.out.println(a[i]);
}
ab:for(i=0;i<a.length;i++){
if(a[i]<0){
count++;
}
}
if(count==n){
System.out.println("0");
System.out.println(2*(a[0]+a[a.length-1]));
}
aa:for(i=0;i<a.length;i++){
for(int j=i+1;j<a.length;j++){

if(a[i]==a[j] && a[i]>0){
System.out.println(a[i]);
for(int o=0;o<a.length;o++){
sum=sum+a[o];
}
System.out.println(sum);
System.out.println(2*(a[0]+a[a.length-

1]));

g++;
System.exit(0);
}
}

}
ab:for(i=0;i<a.length-1;i++)
{
if(g==0 && count<n || a[i]>0)
{
System.out.println(a[i]);
System.out.println(2*(a[0]+a[a.length-1]));
break ab;
}
}
}
}

LOGIC 7:
FIND FIRST REPEATED ELEMENT IN THE GIVEN ARRAY FROM THE FIRST
INDEX:
Rajeev works in the data center lab of the survey department. He has been
assigned the task of identifying “repeated numbers” in a given set of numbers.
He approaches you to help him achieve this.
Given an array of numbers, your task is to return the first repeated number in
the array starting from the first index.
For example – if input1={1,2,4,1,2,8} representing the given array, and
input2=6 representing the number of elements in array, then the result should
be 1 which is the first repeated number in the array. SUM=28
Special conditions should be taken care:

Note 1: You should ignore the negative numbers and zeros. The program
consider only non-zero, non-negative numbers from the given array.
Note 2: If no number is repeated then the output should be the first element
of the array.
Note 3: If all elements in the array are negative or 0’s the output should be 0.
Note 4: Finally ((2*first element from the given array) + (2*last element from
the given array))+10
PROGRAM:
package pattern;
import java.util.*;
public class Ex3 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);

int n=sc.nextInt();
int a[]=new int[n];
int sum=0;
int count=0,i,g=0;
for( i=0;i<a.length;i++){
a[i]=sc.nextInt();
//System.out.println(a[i]);
}
ab:for(i=0;i<a.length;i++){
if(a[i]<0){
count++;
}
}
if(count==n){
System.out.println("0");
System.out.println((2*(a[0]))+(2*(a[a.length-
1]))+10);
}
aa:for(i=0;i<a.length;i++){
for(int j=i+1;j<a.length;j++){
if(a[i]==a[j] && a[i]>0){
System.out.println(a[i]);
for(int o=0;o<a.length;o++){

sum=sum+a[o];
}
System.out.println(sum);

System.out.println((2*(a[0]))+(2*(a[a.length-
1]))+10);

g++;
System.exit(0);
}
}

}
ab:for(i=0;i<a.length-1;i++)
{
if(g==0 && count<n || a[i]>0)
{
System.out.println(a[i]);
System.out.println((2*(a[0]))+(2*(a[a.length-
1]))+10);
break ab;
}
}
}
}

LOGIC 8:
FIND FIRST REPEATED ELEMENT IN THE GIVEN ARRAY FROM THE FIRST
INDEX:
Rajeev works in the data center lab of the survey department. He has been
assigned the task of identifying “repeated numbers” in a given set of numbers.
He approaches you to help him achieve this.
Given an array of numbers, your task is to return the first repeated number in
the array starting from the first index.
For example – if input1={1,2,4,1,2,8} representing the given array, and
input2=6 representing the number of elements in array, then the result should
be 1 which is the first repeated number in the array. SUM=-4
Special conditions should be taken care:

Note 1: You should ignore the negative numbers and zeros. The program
consider only non-zero, non-negative numbers from the given array.
Note 2: If no number is repeated then the output should be the first element
of the array.
Note 3: If all elements in the array are negative or 0’s the output should be 0.
Note 4: Finally ((2*first element from the given array) - (2*last element from
the given array))+10
PROGRAM:

package pattern;
import java.util.*;
public class Ex5 {
public static void main(String[] args) {
Scanner sc=new

Scanner(System.in);

int n=sc.nextInt();
int a[]=new int[n];
int sum=0;
int count=0,i,g=0;
for( i=0;i<a.length;i++){
a[i]=sc.nextInt();
//System.out.println(a[i]);
}
ab:for(i=0;i<a.length;i++){
if(a[i]<0){
count++;
}
}
if(count==n){
System.out.println("0");
System.out.println((2*(a[0]))-

(2*(a[a.length-1]))+10);

}
aa:for(i=0;i<a.length;i++){
for(int j=i+1;j<a.length;j++){
if(a[i]==a[j] && a[i]>0){

System.out.println(a[i]);
System.out.println((2*(a[0]))-(2*(a[a.length-
1]))+10);

g++;
System.exit(0);
}
}

}
ab:for(i=0;i<a.length-1;i++)
{
if(g==0 && count<n || a[i]>0)
{
System.out.println(a[i]);
System.out.println((2*(a[0]))-

(2*(a[a.length-1]))+10);

break ab;
}
}
}
}

LOGIC 9:
FIND FIRST REPEATED ELEMENT IN THE GIVEN ARRAY FROM THE FIRST
INDEX:
Rajeev works in the data center lab of the survey department. He has been
assigned the task of identifying “repeated numbers” in a given set of numbers.
He approaches you to help him achieve this.
Given an array of numbers, your task is to return the first repeated number in
the array starting from the first index.
For example – if input1={1,2,4,1,2,8} representing the given array, and
input2=6 representing the number of elements in array, then the result should
be 1 which is the first repeated number in the array. SUM=42
Special conditions should be taken care:
Note 1: You should ignore the negative numbers and zeros. The program
consider only non-zero, non-negative numbers from the given array.

Note 2: If no number is repeated then the output should be the first element
of the array.
Note 3: If all elements in the array are negative or 0’s the output should be 0.
Note 4: Finally ((2*first element from the given array) * (2*last element from
the given array))+10
PROGRAM:
package pattern;
import java.util.*;
public class Ex4 {
public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

int n=sc.nextInt();
int a[]=new int[n];
int sum=0;
int count=0,i,g=0;
for( i=0;i<a.length;i++){
a[i]=sc.nextInt();
//System.out.println(a[i]);
}
ab:for(i=0;i<a.length;i++){
if(a[i]<0){
count++;
}
}
if(count==n){
System.out.println("0");
System.out.println((2*(a[0]))*(2*(a[a.length-

1]))+10);
}
aa:for(i=0;i<a.length;i++){
for(int j=i+1;j<a.length;j++){
if(a[i]==a[j] && a[i]>0){
System.out.println(a[i]);
g++;

System.out.println((2*(a[0]))*(2*(a[a.length-
1]))+10);

System.exit(0);

}
}

}
ab:for(i=0;i<a.length-1;i++)
{
if(g==0 && count<n || a[i]>0)
{
System.out.println(a[i]);

System.out.println((2*(a[0]))*(2*(a[a.length-
1]))+10);

break ab;
}
}
}
}

LOGIC 10:
FIND FIRST REPEATED ELEMENT IN THE GIVEN ARRAY FROM THE FIRST
INDEX:
Rajeev works in the data center lab of the survey department. He has been
assigned the task of identifying “repeated numbers” in a given set of numbers.
He approaches you to help him achieve this.
Given an array of numbers, your task is to return the first repeated number in
the array starting from the first index.
For example – if input1={1,2,4,1,2,8} representing the given array, and
input2=6 representing the number of elements in array, then the result should
be 1 which is the first repeated number in the array. SUM=10.125
Special conditions should be taken care:
Note 1: You should ignore the negative numbers and zeros. The program
consider only non-zero, non-negative numbers from the given array.
Note 2: If no number is repeated then the output should be the first element
of the array.
Note 3: If all elements in the array are negative or 0’s the output should be 0.

Note 4: Finally ((2*first element from the given array) /(2*last element from
the given array)) +10

Comments

Popular Posts