Zycus Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

<pre lang="" line="1" title="CodeMonkey43364" class="run-this">/* The class name doesn't have to be Main, as long as the class is not public. */
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
java.io.BufferedReader r = new java.io.BufferedReader (new java.io.InputStreamReader (System.in));
String s;
while (!(s=r.readLine()).startsWith("42")) System.out.println(s);
}
}

</pre><pre title="CodeMonkey43364" input="yes">public int findSecondMin(int[] arr){
int secondMin = arr[0];
int min = arr[0];
for(int i=0;i<arr.length;i++) {
if(arr[i]<min || arr[i]<secondMin) {
if (arr[i]<secondMin && arr[i]> min){
secondMin = arr[i];
} else {
secondMin = min;
min = arr[i];
}
}
}
return secondMin;
}</pre>

- Anonymous May 22, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

give this i/p 21 23 34 67 89 90 ur pgm would fail

- durai December 15, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

modify the second to second element of array

- durai December 15, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public int findSecondMin(int[] arr){
int secondMin = arr[0];
int min = arr[0];
for(int i=0;i<arr.length;i++) {
if(arr[i]<min || arr[i]<secondMin) {
if (arr[i]<secondMin && arr[i]> min){
secondMin = arr[i];
} else {
secondMin = min;
min = arr[i];
}
}
}
return secondMin;
}

This function should give the secondMin value in an array

- Prajakta May 22, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

but u have used two if....thats is not allowed

- swapnil December 27, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

min=arr[0];secmin=arr[1];
for(i=1;i<n;i++)
{

if(arr[i]<min)
{

secmin=min;
min=arr[i];
}

else if(secmin>arr[i])
secmin=arr[i];

}

printf("\nmin=%d.....secmin=%d",min,secmin);

- Praneeth May 31, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public int returnMinArr(int[] a){
int low = a[0];
int scndMin = 0;

for(int i=1; i<=a.length-1;i++){
if(a[i]<low){
scndMin = low;
low = a[i];
}
if(a[i]<scndMin&&a[i]>low){
scndMin = a[i];
}
}
return scndMin;
}

- Anonymous June 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static int secondMinimum(int[] arr) {
		int[] mins = new int[2];
		mins[0] = Integer.MAX_VALUE;
		mins[1] = Integer.MAX_VALUE;
		for(int i = 0; i < arr.length; i++) {
			if(arr[i] < mins[1]) {
				if(arr[i] < mins[0]) {
					mins[1] = mins[0];
					mins[0] = arr[i];
				} else {
					mins[1] = arr[i];
				}
			}
		}
		return mins[1];
	}

- sola February 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.io.*;
class Minima
{
public static void main(String args[])
{
System.out.println("Enter size:");
int s=Integer.parseInt(System.console().readLine());
int a[]=new int[s];
System.out.println("Enter elements");
for(int i=0;i<s;i++)
a[i]=Integer.parseInt(System.console().readLine());
int m1=a[0],m2=-9999,c=0;
for(int i=0;i<s;i++)
{
if(a[i]<m1 && a[i]>m2)
{
m1=a[i];
}
if(i==s-1 && c==0)
{
i=-1;
c++;
m2=m1;
m1=999;
}
}
System.out.println("Minimum element:"+m2+"\n2nd minimum:"+m1);
}
}

- JyoGo September 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I had a doubt, all the above programs are absolutely right, but what about the condition when there are duplicate elements in the array such as 100,98,99,99

- Manish Sharma December 18, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/**
	 * 
	 * @author Alam Mustaque
	 * Write a java code to find the second minimum element in an array using single loop.
	 */
	public void secondMinimum(){
		int[] arr = {4,30,20,100,700,900,0,9,8,6,1,3};
		for(int ar:arr){
		System.out.print(" "+ar);
		}
		int min=arr[0];
		int smin = arr[1];
		
		for(int i=2;i<arr.length;i++){
			if(arr[i]<min || smin<min){
				smin=min;
				min=arr[i];
			}
			if(arr[i]>min && arr[i]<smin){
				smin=arr[i];
			}
		}
		System.out.println("\n Secon min is "+smin+" min = "+min);

}

- Mustaque Alam April 25, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/**
*
* @author Alam Mustaque
* Write a java code to find the second minimum element in an array using single loop.
*/
public void secondMinimum(){
int[] arr = {4,30,20,100,700,900,0,9,8,6,1,3};
for(int ar:arr){
System.out.print(" "+ar);
}
int min=arr[0];
int smin = arr[1];

for(int i=2;i<arr.length;i++){
if(arr[i]<min || smin<min){
smin=min;
min=arr[i];
}
if(arr[i]>min && arr[i]<smin){
smin=arr[i];
}
}
System.out.println("\n Secon min is "+smin+" min = "+min);
}

- Mustaque Alam April 25, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

wat the fuck

- Anonymous July 08, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int min=arr[0],secmin=arr[1];
for(int i=1;i<arr.length;i++)
{
if(arr[i]<min)
{
secmin=min;
min=arr[i];
}
}
System.out.println("The second minimum in the array is"+secmin);

- Anonymous September 22, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int min=arr[0],secmin =arr[1];
for(int i=1;i<arr.length;i++)
{
if(arri[i]<min)
{
secmin=min;
min=arr[i];
}
}
System.out.println("The second minimum is"+secmin):

- aa1992 September 22, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Test9 {

	public static void main(String[] args) {
		// find second lowest number
		int[] input = {31,22,13,54,45,26,87,18,39,60};
		int lowestNum = 100000;
		int targetNum = 10000;
		
		for(int i = 0; i < input.length;i++){
			if(input[i] < targetNum){
				targetNum = input[i];
			}else if(targetNum < lowestNum){
				// swap
				int temp = 0;
				temp = targetNum;
				targetNum = lowestNum;
				lowestNum = temp;
			}
			
		}
		System.out.println("target Num : "+targetNum);
		System.out.println("lowest Num : "+lowestNum);
	}

}

- mannerh1 January 19, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static int findSecondMin2(int[] arr) {
int min = arr[0], secondMin = arr[0];
for (int i = 0; i < arr.length; i++) {
if(min>arr[i]) {
min=arr[i];
} else if(secondMin>arr[i] || min==secondMin) {
secondMin=arr[i];
}
}

return secondMin;
}

- swapnils March 27, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static int findSecondMin2(int[] arr) {
int min = arr[0], secondMin = arr[0];
for (int i = 0; i < arr.length; i++) {
if(min>arr[i]) {
min=arr[i];
} else if(secondMin>arr[i] || min==secondMin) {
secondMin=arr[i];
}
}
return secondMin;
}

- swapnils March 27, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1.take array for eg a[]={5 ,6,1,9,7,4}
2.sort array element in ascending order then a[]={1,4,5,6,7,9}
3.for finding 2nd minimum element by using index value we can find second minimum no
   System.out.println("2nd min no="+a[1]
it will print  2nd min no=4

- Anonymous February 06, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

let arr = [4,30,20,100,700,900,0,9,8,6,1,3]
var min=arr[0]
var secmin=arr[1]
for(let i=0;i<arr.length;i++)
{

if(arr[i]<min)
{

secmin=min;
min=arr[i];
}

else if(secmin>arr[i])
secmin=arr[i];

}
console.log("second minimum element in an array", min,secmin)

- satyam kumar June 15, 2022 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

let arr = [4,30,20,100,700,900,0,9,8,6,1,3]
var min=arr[0]
var secmin=arr[1]
for(let i=0;i<arr.length;i++)
{

if(arr[i]<min)
{

secmin=min;
min=arr[i];
}

else if(secmin>arr[i])
secmin=arr[i];

}
console.log("second minimum element in an array", min,secmin)

- satyam kumar June 15, 2022 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

public class JavaApplication1 {

public static void main(String[] args)
{
int i;
int[] n=new int[]{2,10,90,52,30,67,93,45,1,78,40,88};
int m1=n[0],m2=n[1];
for(i=0;i<n.length;i++)
{

if(m1>n[i] || m2>n[i] && m1>m2)
{
m2=m1;
m1=n[i];
}

}
System.out.println("2nd min "+m2);
}
}

- Amit Lopes March 12, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

wat an answer amit!!!!!!

- Anvay March 13, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

doesnt work if the array is 4,3,2,1 ie. in descending order

- ankur September 22, 2013 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More