Expedia Coding Interview

Pranav Chaturvedi
1 min readSep 28, 2020

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:

--

--