Amazon interview | 我在亚马逊的通关秘籍:从面试小白到拿到 offer,一路干货分享!

1,281Views
尚無留言

要說拿到 亚马逊 的 offer,那可真不是件容易事兒。 作為全球數一數二的科技巨頭,亞馬遜的面試標準出了名的高,不光看你技術牛不牛、解決問題能力強不強,還得看你跟他們那套著名的領導力準則合不合拍。

無論你是想進軍軟體工程,還是立志成為產品經理,問對問題都能幫你摸清門道,找到成功的秘訣。 接下來的分享,咱們就來聊聊那些亞馬遜面試里的「真題」,給你一些獨家見解和應戰策略,讓你能自信滿滿地去面試,從一眾高手中脫穎而出!

Amazon interview

Amazon Interview Code 1:電商套利利潤最大化

設想你是一名電商套利者,計劃在促銷季節從一家大型零售商(例如沃爾瑪)低價購入商品,然後在另一個電商平臺(例如亞馬遜)上以更高的價格賣出,以此獲得利潤。 你的任務是確定最佳的購買和銷售時機,以實現最大的利潤。

給定兩個陣列,分別代表在連續幾天內,同一商品在沃爾瑪和亞馬遜的每日價格。 你的目的是找出一個購買和銷售的時機組合,使得利潤最大化。

輸入:

  • walmart_prices[]:一個整數陣列,表示連續幾天內沃爾瑪的商品價格。
  • amazon_prices[]:一個整數陣列,表示連續幾天內亞馬遜的商品價格。

輸出:一個整數,表示能夠實現的最大利潤。

示例:

輸入:

  • walmart_prices = [4, 7, 5, 8]
  • amazon_prices = [6, 8, 7, 8]

輸出:4

解釋:你可以在第 0 天以 4 美元的價格從沃爾瑪購買商品,在第 1 天以 8 美元的價格在亞馬遜賣出,從而獲得 4 美元的利潤。

注意:

  • 你可以假設兩個陣列的長度相同,且每天只能進行一次交易(即只能購買或銷售一次商品)。
  • 如果沒有利潤可圖,輸出應為 0。

面試過程:

首先面試官和候選人進行了短暫的自我介紹:

在面試過程中,面試官深入探討了候選人過往的職業經歷,特別是其參與的關鍵項目細節,旨在評估其實際解決問題的能力。 候選人分享了近期通過技術創新,顯著提升系統運行效率的經歷。 他強調了自身對數據結構與演算法深刻理解的運用,這些專業知識成為他優化系統性能、實現性能的手段。 通過實例闡述,候選人不僅展現了其技術實力,還體現了將理論知識靈活應用於實踐場景的能力。

面試官:聽起來很不錯,那接下來我們進入技術面試環節?
候選人:好的,沒問題

接下來是一道代碼程式設計題:

面試官提出了一個代碼問題,如何通過策略性地選擇,在 Walmart 購買商品並在 Amazon 平臺上出售,以實現利潤最大化的目標。 候選人迅速捕捉到了問題的核心要點,並理解了問題。 為了進一步確保對問題的全面把握,候選人提出了一系列澄清問題。

澄清問題:

候選人繼續深入提問,以便全面地理解問題場景和邊界條件:“這道題的意思是我們要尋找在 Walmart 購買並在 Amazon 出售的最大利潤,對嗎? “這再次確認了候選人對問題目標的準確理解。”
面試官給予肯定回答后,候選人進一步提出:“好的,兩者的價格清單是相同的嗎? ”
面試官明確回復:“是的,兩個列表的長度相同,每個時間點上的價格對應相同的商品。 ”
候選人考慮到了特殊情況,提出:“那麼如果 Walmart 的價格始終高於 Amazon 的價格,我們可以假設賣家將不會進行交易嗎? ”
面試官的肯定回答:“是的,買家可以策略性的選擇是否交易,沒有買入賣出的話,利潤是 0”

代码思路:

候選人開始詳細闡述其解決方案:採用動態規劃的思想,但實際上,在這個特定問題中,更接近於一種滑動視窗或單次遍歷的優化策略。 候選人計劃用一個變數來動態追蹤到目前為止在 Walmart 看到的最低價格,這是一個聰明的策略,因為它允許在遍歷 Amazon 價格時,迅速計算出基於當前最低 Walmart 價格的潛在利潤。
面試官對候選人的思路表示了認可:”思路没问题,那么这样设计的时间复杂度是多少呢?”
候選人準確地指出:”由于只遍历了一次价格列表,因此时间复杂度是O(n),其中n是价格列表的长度。”

面試官的對候選人的回答進行了肯定,並提出如何處理邊界情況、如何確保代碼的正確性以及如何在實際應用中驗證和優化演演算法時間複雜度等方面。

細節問題討論:

面試官接著問:“假設 Walmart 的價格始終高於 Amazon,該怎樣挑選合適的策略呢? ”
候選人:”这种情况下,买家不会发生任何交易,利润为0。”
面試官:“所以能否考慮到其他邊界條件呢? ”
候选人迅速回应:“如果兩個列表的長度不相等或者價格清單為空。 對於這些問題,需要確保輸入有效,這在實際程式設計中是非常重要的,因為不合法的輸入往往會導致程式出錯或產生不可預測的結果。 ”
面試官:“不錯,解決思路沒有問題。 那請開始實現一下代碼吧”

Clarification Question:

Candidates: “So can Walmart Sellers assume that they can buy from Walmart first and then wait for Amazon to provide better pricing?”

The interviewer followed up with “Yes, So the customer can wait and get a price that is lower Amazon in future date after purchasing an item from Walmart”

Code Question Discussion:

The candidate stressed the need to resolve it efficiently. She stressed the necessity to track all Walmart prices seen so far and calculate their profit ateach step, before calculating what Amazon would make from each price change. She further detailed declaring initial variables such as minimum price fromWalmart or maximum profit and updating profit calculations at every Amazon price step until reaching maximum profits so far.

Interviewer liked the proposed technique and advised candidate to implement it immediately.

Follow-up Questions:

The interviewer asked: “Assuming Walmart’s prices are always higher than Amazon’s, How we choose a suitable strategy to buy goods?”
候選人: “In this case, we will not make any transactions and the profit will be zero.”
訪問員: “Let’s consider other boundary conditions.”
The candidate responded: “If the lengths of two lists are not equal or the price list is empty, it is important to ensure that the input is valid for these issues, asinvalid input often leads to program errors or unpredictable results.”
訪問員: “Great, there is no problem with the solution idea. Then please start implementing the code.”

Amazon Interview Code 2:合併 N 個有序清單

Question:

我在亞馬遜的通關秘笈:從面試小白到拿到 offer,一路乾貨分享!

Example:

我在亞馬遜的通關秘笈:從面試小白到拿到 offer,一路乾貨分享!

面試過程:

代碼題目問答

候選人提問深入:進一步明確了任務的核心,即需要將多個已排序的清單合併成一個單一的、同樣保持有序的新清單。 緊接著提出了解題方法:「在合併這些清單時,是否可以藉助優先佇列(特別是最小堆 min-heap)來優化這一過程呢? 通過構建最小堆來動態追蹤每個清單的當前最小元素,我們能夠實現一個較為高效的合併演算法,其時間複雜度大約為 O(N log k),這裡 N 代表所有清單中的元素總數,k 則是清單的個數。 這樣的方法能否適用於我們的場景? ”

面試官給予了肯定的反饋:“你的思路非常清晰且正確。 利用最小堆來輔助合併多個有序清單,確實是一個有效的優化手段。 這種方法不僅保持了合併後清單的有序性,還通過減少不必要的比較次數,顯著提升了演算法的效率。 ”

代码思路:

候選人提出的使用 min-heap(最小堆)來合併多個有序清單的思路是非常清晰和有效的。 以下是該思路的詳細步驟,以及每一步的解釋:

  1. 初始化優先佇列(min-heap):創建一個最小堆,用於存儲來自各個有序清單的當前最小元素。
  2. 迭代处理最小堆:在一個迴圈中,不斷從最小堆中取出當前的最小元素(即堆頂元素),並將其添加到結果清單中。
  3. 合併結果‌:当最小堆为空时,表示所有列表的元素都已经被处理完毕。

Clarification Question:

The candidate asked: “Are we combining multiple sorted lists into one?

The interviewer replied, “Yes, while merging multiple sorted list,the resultant has to be a single sorted array”.

Code Discussion:

The product guy elaborated upon two alternatives(predictions). One is the brute force method of simply concatenating every list together and then sorting that resulting collection which takes O(N log N) time, where Nrepresents the total number of elements. The second approach made more sense: Candidate had advised using a min-heap (priority queue) to easily merge thelists in an optimized way.

It required the initialisation of a min heap with minimum element from each list. Such candidate would keep extracting smallest element and pushing thenext successor from that list until all elements were merged. This one gives you O(N log k) complexity, with respect to the number of lists which is denotedhere as k.

The interviewer was pleased with that answer, recognizing the potential time savings, and asked for coding to begin.

更多資訊

Interviewing at Amazon

Amazon job interview mistakes

We assist you with the interviews and proxy interview services so that your chances of getting into your dream company are perfected. Get in touch with us any time.

如果你面試、筆試有問題,請隨時聯繫我,專業協助您通過筆試、面試,歡迎隨時咨询我

author avatar
ProgramHelp
END
 0
Comment(尚無留言)