Microsoft Interview Question

Design and implement a "inner join" function using 2 sorted lists/arrays. Make it run in O(n) time.

Interview Answers

Anonymous

May 26, 2020

//MERGING SORTED LIST public ListNode mergeTwoLinkedList(ListNode list1,ListNode list2,ListNode list3) { ListNode dummy=new ListNode(-1); ListNode head=dummy; dummy.next=list1; dummy=dummy.next; ListNode current=dummy; while(current.next!=null) { current=current.next; } current.next=list2; current=current.next; while(current.next!=null) { current=current.next; } current.next=list3; return head.next; }

Anonymous

May 26, 2020

//MERGING SORTED ARRAYS public static int[] merge(int[] a,int[] b) { int m=0;int n=0; int k=a.length+b.length; int[] c=new int[k]; int j=0; while(m