Amazon Interview Question for Software Engineer / Developers


Country: India




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

do we need to do anything here when it is only the read operations.

- DashDash April 21, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Dont put critical section in synchronized block.

- Vipin Sharma April 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

As long as the resource in critical section is immutable, no need to do anything.

- kuldeep April 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

static ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
	public void readMethod()
	{
		lock.readLock().lock();
		//read something
		lock.writeLock().unlock();
	}

	public void writeMethod()
	{
		lock.writeLock().lock();
		//read something
		lock.writeLock().unlock();
	}

- JDev April 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

-> You can use ConcurrentHashMap, which allows multiple reads can happen if no write operation is going on.

- Prashanth April 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

-> You can use ConcurrentHashMap, which allows multiple reads can happen if no write operation is going on.

- Prashanth April 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We dont even need a critical section if no one is writing anything.

- mukulbudania April 25, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You might have misinterpreted the question. There could be write happening, and when it does happen, nobody should be able to read.

- JDev April 26, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

use read-write lock as in pthreads

- Anonymous May 20, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

readCount=0;
mutex=0;

Reading:

while(writelock == true);
writelock=true;
while(mutex==1);
mutex=1;
readCount++;
mutex=0;

---------
READ
---------

while(mutex==1);
mutex=1;
readCount--;
mutex=0;
writelock=false;




Writing:

while(readLock >0 && writelock==true)
{
writelock=true;
---------
WRITE
---------
writelock=false;
}

- monj June 18, 2013 | 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