Cisco Systems Interview Question for Software Engineer / Developers


Team: Nexus
Country: United States
Interview Type: In-Person




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

void f(int a[]; n)
{
int k;
for(k = 0; k < n; k++)
{
if (a[k] > a[(k+1) % n]);
break;
}
printf(“The minimum is: %d”, a[(k+1) % n];
printf(“The second minis: %d”, a[(k+2) % n];
printf(“The second max is: %d”, a[(k+n-1) % n];
}

- lliyanc April 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Linear complexity, I believe the optimal method should be logarithmic

- koppie644 November 22, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yes, you can find the rotation amount (and direction) in O(log n) time (assuming all elements are distinct).

Once you do that, all the kth minimum queries are O(1).

- Anonymous November 22, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Use tournament sort.

- Nanjundi_Kalyana January 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

#include<iostream>
#include<conio.h>
using namespace std;

int main() {
int a[10]={7,8,9,10,1,2,3,4,5,6};
int i=0;
while(a[i]<a[(i+1)%10])
i++;
cout << a[(i+1)%10] << endl;
cout << a[(i+2)%10] << endl;

getch();
return 0;
}

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

Wouldn't rotating multiple times be the same as rotating once by the sum of all rotations?

- eugene.yarovoi January 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yes, if you are told how many steps of rotations are done. Here it is unknown entity.

- AmzFAILFacebookFailMSFTFail January 20, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yes, if you are told how many steps of rotations are done. Here it is unknown entity.

- AmzFAILFacebookFailMSFTFail January 20, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

BTW, on personal front, you seem to be good contributor to this site ( I'm quantifying you on your 300+ comments). What are you upto? Sophomore or junior or senior :) ?

- AmzFAILFacebookFailMSFTFail January 20, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Wow, has it been 300? And I guess that's
not even counting any posted as anonymous.

I'm beginning my career next month at a company. How about you?

- eugene.yarovoi January 21, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

#include<iostream>
#include<conio.h>
using namespace std;

int main() {
int a[10]={8,9,10,1,2,3,4,5,6,7};

int i=0; //start index
int j=4; //middle index
int k=9; //array.length-1

while(i!=j) {
if(a[i]<a[j] && a[j]<a[k]) {
k=j;
j=(i+k)/2;
}
else if(a[i]<a[j] && a[j]>a[k]){
i=j;
j=(j+k)/2;
}
else if(a[i]<a[j]) {
k=j;
j=(i+k)/2;
}
else if(a[i]>a[j] && a[j]<a[k]) {
k=j;
j=(i+k)/2;
}
}

cout << "Minimum two elements: " << endl;
if(a[i]<a[k]) {
cout << a[i] << endl;
cout << a[i+1] << endl;
}
else
cout << a[k] << endl;
cout << a[k+1] << endl;

getch();
return 0;
}

- knoesis January 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If a complete sorted array is rotated (i assume it is not rotating w.r.t. some point inside array as it is not written), then it is still a sorted array but in opposite order. So how many times it is rotated is not a matter. Only we have to check if first element in greater than the second, it is minimum number and second is second minimum and similarily for maximum.

- Mad Coder February 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

can u please explain your point with the help of an example

- vision February 18, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

#include<iostream>
#include<conio.h>
using namespace std;

int main() {
int a[10]={7,8,9,10,1,2,3,4,5,6};
int i=0;
while(a[i]<a[(i+1)%10])
i++;
cout << a[(i+1)%10] << endl;
cout << a[(i+2)%10] << endl;

getch();
return 0;
}

- Anonymous February 23, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

If a complete sorted array is rotated (i assume it is not rotating w.r.t. some point inside array as it is not written), then it is still a sorted array but in opposite order. So how many times it is rotated is not a matter. Only we have to check if first element in greater than the second, it is minimum number and second is second minimum and similarily for maximum.

- Mad Coder February 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If a complete sorted array is rotated (i assume it is not rotating w.r.t. some point inside array as it is not written), then it is still a sorted array but in opposite order. So how many times it is rotated is not a matter. Only we have to check if first element in greater than the second, it is minimum number and second is second minimum and similarily for maximum.

- Mad Coder February 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

struct Pair
{
int min;
int max;
}

struct Pair GetMin(int arr[], int low, int high)
{
struct Pair MinMax, Left, Right;
If (low==high)
{
MinMax.min=arr[low];
MinMax.max=arr[high];
return MinMax;
}

If(low=high+1)
{
MinMax.min=((arr[low]<arr[high])?arr[low]:arr[high]);
MinMax.max=((arr[low]>arr[high])?arr[low]:arr[high]);
return MinMax;
}
int mid=(left+right)/2;
Left=GetMin(arr,low,mid);
Right=GetMin(arr,mid+1,high);


MinMax.min=((Left.min)<(Right.min))?Left.Min:Right.Min;
MinMax.max=((Left.max)>(Right.max))?Left.max:Right.max;

return MinMax;
}

- Avinash February 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<conio.h>
using namespace std;

int main() {
int a[10]={7,8,9,10,1,2,3,4,5,6};
int i=0;
while(a[i]<a[(i+1)%10])
i++;
cout << a[(i+1)%10] << endl;
cout << a[(i+2)%10] << endl;

getch();
return 0;
}

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

#include<iostream>
#include<conio.h>
using namespace std;

int main() {
int a[10]={7,8,9,10,1,2,3,4,5,6};
int i=0;
while(a[i]<a[(i+1)%10])
i++;
cout << a[(i+1)%10] << endl;
cout << a[(i+2)%10] << endl;

getch();
return 0;
}

- awanish February 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<conio.h>
using namespace std;

int main() {
int a[10]={7,8,9,10,1,2,3,4,5,6};
int i=0;
while(a[i]<a[(i+1)%10])
i++;
cout << a[(i+1)%10] << endl;
cout << a[(i+2)%10] << endl;

getch();
return 0;
}

- awanish February 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<conio.h>
using namespace std;

int main() {
int a[10]={7,8,9,10,1,2,3,4,5,6};
int i=0;
while(a[i]<a[(i+1)%10])
i++;
cout << a[(i+1)%10] << endl;
cout << a[(i+2)%10] << endl;

getch();
return 0;
}

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

#include<iostream>
#include<conio.h>
using namespace std;

int main() {
int a[10]={7,8,9,10,1,2,3,4,5,6};
int i=0;
while(a[i]<a[(i+1)%10])
i++;
cout << a[(i+1)%10] << endl;
cout << a[(i+2)%10] << endl;

getch();
return 0;
}

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

Cisco gives hike once in 2-3 years.

New-Joinees only get hike after 2-3 years, so take 100% hike at the time of joining .. . otherwise don't cry after joining. :)

- Simple April 25, 2014 | 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