## ASAPInfosystemsPvtLtd Interview Question for Associates

• 0
of 0 votes

Country: India
Interview Type: Written Test

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

Can anyone clarify this problem ? What are we solving?

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

``````def setNearestMinimum(arr):
op = [99 for x in xrange(len(arr))];
stack = [];
for pos in xrange(len(arr)):
if len(stack) == 0 or pos == 0:
op[pos] = min(op[pos], -1);
stack.append(pos);
else:
while len(stack) > 0 and arr[stack[-1]] > arr[pos]:
stack.pop();
op[pos] = min(op[pos], stack[-1] if len(stack) > 0 else -1);
stack.append(pos);

stack = [];
for pos in xrange(len(arr) - 1, -1, -1):
if len(stack) == 0 or pos == len(arr) - 1:
if op[pos] == -1:
op[pos] = min(op[pos], -1);
stack.append(pos);
else:
while len(stack) > 0 and arr[stack[-1]] > arr[pos]:
stack.pop();
if op[pos] == -1:
op[pos] = stack[-1];
else:
op[pos] = stack[-1] if stack[-1] - pos < pos - op[pos]  else op[pos];
stack.append(pos);

for pos in xrange(len(op)):
if op[pos] == -1:
print(-1);
else:
print(arr[op[pos]]);
return;

setNearestMinimum([1, 200, 30, 1000, -6]);``````

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