Java interview with an Amazon engineer: Median of sorted list

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 พ.ย. 2024

ความคิดเห็น • 9

  • @interviewingio
    @interviewingio  3 ปีที่แล้ว +1

    Want to give it a shot?? Sign up with us to make sure your upcoming interviews are the best they can be by practicing with our experienced engineers. interviewing.io/signup?.com&

    • @soundnarcotics3417
      @soundnarcotics3417 3 ปีที่แล้ว

      If we interview does ours have to be posted on TH-cam?

    • @interviewingio
      @interviewingio  3 ปีที่แล้ว

      @@soundnarcotics3417 Absolutely not! The interviews we publish are those that both the interviewer and interviewee both gave permission. Let us know if you have any other questions!

  • @sandippatel2605
    @sandippatel2605 3 ปีที่แล้ว +1

    For the first problem, can anyone explain time complexity ( how it is o(n) ). it looks a like n^2 . correct me if i am wrong.

  • @arnabofdigha
    @arnabofdigha 3 ปีที่แล้ว

    The first solution he provided, it has n^2 time complexity... not n as he mentioned.
    The 2nd problem was not this difficult. If size of both array is m and n, median will be at floor((m+n)/2)th position of marged array. marge both array till (m+n)/2 position (As rest of the items doesn't matter) and peek the last item. You have the solution in linier time complexity.

    • @feuerfawkes
      @feuerfawkes 3 ปีที่แล้ว +8

      Your analysis of the first solution is wrong; the time complexity is indeed O(n) because each element in the array and stack is accessed or popped only once. Your solution to the second problem is suboptimal; it can be solved in O(log(min(n, m))) time using binary search.

    • @conan842002
      @conan842002 ปีที่แล้ว

      @@feuerfawkes You are absolutely wrong about the complexity of the first problem. The complexity is indeed O(n^2). How come the stack is accessed and popped only once? Have you tried counting how many times it gets accessed and popped?

  • @twndomn
    @twndomn 3 ปีที่แล้ว

    Interviewer should fail the interviewee for using Java stack. Java stack is known to be inefficient and obsolete, should use Deque instead.

    • @jontag77
      @jontag77 3 ปีที่แล้ว +19

      That would be a terribly poor reason to fail someone during an interview. The point of an interview is to test your critical thinking and problem solving skills. You could literally teach someone that Deque is more efficient then Java stack in 3 seconds. You can not teach someone how to problem solve and think critically in 3 seconds though.