Expedia Coding Interview SDE-1 Gurgaon

Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2020-09-28Added By Anonymous
Source: Link
Expedia | SDE-1 | Phone Screen | Gurgaon | Unknown Round 1 (Coding and Problem solving round held on bluejeans) http://collabedit.com/ was used for code sharing , the video and screen share were on throughout the interview Question 1: Given an array of stock prices with index representing the days, return the maximum profit . The user can buy only once and sell only once. The buy and sell date cannot be same. It is a similar leetcode question: https://leetcode.com/problems/best-time-to-buy-and-sell-stock/ def maxProfit(self, prices: List[int]) -> int: minCostPrice,maxSellPrice=float(‘inf’),float(‘-inf’) if(len(prices)==0): return 0 for i in range(len(prices)): if(minCostPrice>prices[i]): minCostPrice=prices[i] maxSellPrice=max(maxSellPrice,prices[i]-minCostPrice) return maxSellPrice Question 2: Construct a stack with functions Push: Push an Element in a stack(i.e. at the top) Pop: Pop an element (i.e. remove an element from top) Min_value_in_stack: returns minimum value in stack at any point Similar question on leetcode: https://leetcode.com/problems/min-stack/ def __init__(self): self.stck=[] # print(self.stck) def push(self, x: int) -> None: if(len(self.stck)==0): self.stck.append([x,x]) # print(self.stck) else: self.stck.append([x,min(self.stck[-1][1],x)]) # print(self.stck) def pop(self) -> None: if(len(self.stck)>0): self.stck.pop() # print(self.stck) def top(self) -> int: if self.stck: return self.stck[-1][0] # print(self.stck) def getMin(self) -> int: return self.stck[-1][1] Round 2(Coding and Data Structures Round) Held on Bluejeans video call and code in http://collabedit.com/ Question : What is Binary Search Tree(BST)? (Answer: Specify the conditions) Question:Why this example is not a BST ?(Answer: 3 cannot be in the right side of root node 5) 5 3 7 2 4 38 Question:What are some applications of BST? (Answer: Application related to searching as time complexity is O(logn), the inorder traversal gives a sorted order (so can store values to be in sorted order) Question: Give Order Traversals of a tree Pre: root,left,right In: left,root,right Post: left,right,root def preorder(root): if(root==None): return print(root.val) self.preorder(root.left) self.preorder(root.right) def inorder(root): if(root==None): return self.inorder(root.left) print(root.val) self.inorder(root.right) def postorder(root): if(root==None): return self.postorder(root.left) self.postorder(root.right) print(root.val) Question : Give an array having numbers from 1 to n , where 2 numbers are missing. Find the two missing numbers. Answer: Sorted: Apply linear search or binary serach Not sorted : Try applying average and sum formula `Snippet for the equations`: a:1 to n ideal_sum=n*(n+1)/2 curr_sum=sum(a) diff=ideal_sum-curr_sum x+y=diff 1<=x,y<=n ideal_sum-x-y/n=(n+1)/2-x/n-y/n Question : Given a linked list with duplicate elements , sum up the duplicates and return the end result (do not use extra space like map to store frequency) 1->2->2->3->3->3->9->None 1->4->9->9->Null 1->4->18->NULL `Snippet of Code`: new_val=0 while(ptr.next!=None): if(ptr.next.val==ptr.val): new_val+=ptr->next.val else: if(new_val!=0): intial_pos.val=new_val intial_pos.next=ptr.next new_val=ptr.next.val new_val=0 ptr=ptr.next
Comments