Amazon Interview Question for Quality Assurance Engineers


Country: India




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

Can be resolved using PriorityQueue

- Amrish October 25, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Solution with PriorityQueue is not the best solution, since you using additional space. It can be done without PrirorityQueue using two indexes for pos and neg - O(n) time

- Yavorsky.Yuriy October 31, 2019 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

def sort_positive_negative(arr):
    i = 0
    while i<len(arr)-1:
        if arr[i]>0 and arr[i+1]<0:
            i += 2
        elif arr[i]<0 and arr[i+1]>0:
            arr[i], arr[i+1] = arr[i+1], arr[i]
            i += 2
        else:
            postive = 1
            if arr[i]>0:
                postive = -1
            for j in range(i+2, len(arr)):
                if postive*arr[j]>0:
                    arr[j-1], arr[j] = arr[j], arr[j-1]
                    break
    return arr


if __name__=='__main__':
    data = [
         [
          [-1, 6, 9, -4, -10, -9, 8, 8, 4],
          [6, -1, 9, -4, 8, -10, 8, -9, 4]
         ]
        ]

    for d in data:
        print('input', d[0], 'sort postive-negetive', sort_positive_negative(d[0]), 'expected', d[1])

- Loghman Barari October 27, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def sort_pos_neg(il):
    for i in range(len(il)):
        if i % 2 == 0:
            # @i expects a positive num
            if il[i] < 0:
                for j in range(i+1, len(il)):
                    if il[j] >= 0:
                        # Swap the items @ i and j
                        il[j], il[i] = il[i], il[j]
                        break
        else:
            # @i expects a negative num
            if il[i] >= 0:
                for j in range(i+1, len(il)):
                    if il[j] < 0:
                        # Swap the items @ i and j
                        il[j], il[i] = il[i], il[j]
                        break

    return il

- lvphuc133 November 08, 2019 | 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