Chronus Interview Question for Software Engineer / Developers






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

you want to find first missing number.

Negate the element on the index for current element. in the second loop check for positive number on an index& index is solution

for i=0;i<n;i++
a[a[i]-1] = -a[a[i]-1];

for i=0;i<n;++i
if(a[i] > 0)
printf("missing number is %d", i+1);

- Rahul D August 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

will there be more than one missing element.

- Raquibur August 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Array containing Elements 1...n only? So you can put each element i in index i-1 and check again for those which aren't at their index.

- Rsl August 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Add the numbers given in that array. Let it be S. Subtract S from n*(n+1)/2. You will get the missing number.

- Kishore Jinka August 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Xor is better than sum.
n*(n+1)/2 may overflow, say when n is 1000,000 and you don't have 64 bit integer data type. Of course you can use double, but double has some precision problem.

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

Elements are repeated so summing or XORing will not work

- Algo Visa August 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;

public class NewClass {

public static void main(String[] args)
{
int [] arr = { 1, 2, 3, 3, 5, 6, 7};

int redundant = 0 ;
int arrSum = 0;
int peg = 0;
for (int i = 0; i< arr.length; i++)
{
if (arr[i] != i +1)
{
redundant = redundant + arr[i];
peg = i+1 - arr[i];
}
arrSum = arrSum + arr[i];
}
int realSum = arrSum - redundant;
int actualSum = (arr.length *(arr.length +1))/2;
int diff = actualSum - realSum;

System.out.println(String.format("Actual Sum = %d:: Real Sum = %d",actualSum, realSum));

System.out.println(String.format("Missing Number = %d",diff));
}

}

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

Is the Array sorted and will there be only one number repeated ??

- Pradeep August 09, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
main( )
{
int arr[]= {2,1,8,5,4},arr_size,sub[100],i,ans;
arr_size=(sizeof(arr))/4;
for(i=0; i<arr_size; i++)
sub[i]=0;
ans=fun(&arr, &sub,arr_size);
printf("%d",ans);
}
int fun(int arr[ ], int sub[ ],int arr_size)
{
int val,i;
for(i=0; i<arr_size; i++)
{
val=arr[i];
if(((sub[val-1])==0)&&(val<=arr_size))
{
sub[val-1]=val;
}
else
{
for(i=0; i<arr_size; i++)
{
if(sub[i]==0)
return(i+1);
}
}
}
}

- karthik September 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@all There can be more than one missing element also and are not sorted too..!!

- keerthy January 04, 2012 | Flag Reply


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