Cisco Systems Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

It is a variation of producer-consumer problem.
How about this.

Use a Hashtable with two fields.
(Token Number range(1001,2000) and Status(Free or Busy))

hashtable ht;

int allocate()
{
test = false
while(test == false)
{ 
  lock.acquire(ht);
  val = find first entry with (status == free)
  if(val != -1)
           test = true;
           assign it to the token and change the status to 'busy'
           lock.release(ht);
  else
          lock.release(ht);
          sleep();
}

void  release(int token)
{
    lock.acquire(ht);
    stat = ht.find(token); 
    if(stat == -1)
        print "Token does not exist/ Cannot delete"
        lock.release(ht)
        return 0
    else 
        Change status of that location to 'free'
         lock.release(ht)
         return val
}

- razorf9 July 05, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Semaphore  availableSem = 1000;
Semaphore  usedSem = 0;
int A[1000] = {1001, 1002, ,,,, 2000};
int start = 0;
int end = 999;

int allocate_token()
{
	int retToken = 0;
	p(availableSem);
	retToken = A[start];
	start = (start+1)%1000;
	v(usedSem);
}


void free_token(int token)
{
	p(usedSem);
	end = (end+1)%1000;
	A[end] = token;
	v(availableSem);
}

- Jason October 21, 2013 | 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
Comment hidden because of low score. Click to expand.
-1
of 1 vote

take 2 semaphores freetoken(initialized to 1000) and allocatedtoken(initialized to zero) one global variable tokennumber(intialized to 1000) and one mutex m to provide mutual exclusion on token number


int allocatetoken()
{
wait(freetoken)
wait(m)
return tokennumber++;
signal(m)
sigal(allocatedtoken)

}



void freetoken()
{
wait(allocatedtoken)
wait(m)
return --tokennumber;
signal(m)
sigal(freetoken)

}

I think its producer consumer problem variation only

- Anonymous July 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think the buffer should be considered as circular queue.
Initialise the tokennumber with -1.
and inside allocatetoken()
tokennumber=(++tokennumber)%1000 + 1001.

- Aashish July 01, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Say all tokens are allocated and now token no. 1002 is freed, how will you reallocate this token?

- loveCoding July 01, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@manan...it will check in allocatetoken to find out which token is free ..use for loop to check which token is free.... u can use for loop in wait() function only...

- amnesiac July 02, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I dont see any oop in the above code

- loveCoding July 02, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

write a wait function such that it will search for which token is free.. if nothing is free then it will go in infinite loop till anyone one the token gets free.

- amnesiac July 02, 2012 | 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