## ASAPInfosystemsPvtLtd Interview Question for Associates

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]);``````

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.

### 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.