----------------------------------------------------------------------------------------------------------------
Instagram:
Twitter:
Patreon:
GitHub:
This is one of Amazon's most commonly asked interview questions according to LeetCode (2019)! rotting oranges coding solution. If you give me 10 minutes you'll thank me if this appears during your Amazon interview! Coding Interviews rotting oranges (LeetCode) question and explanation.
DISCORD CHANNEL
----------------------------------------------------------------------------------------------------------------
To join the Discord channel use the following link and join the "Member" tier: In this Discord channel, you will be able to...
1. Ask me questions directly (as well as other members)
2. Ask about and discuss previous interview experiences
3. Find mock interview partners
4. Share helpful videos for interview preparation, and more!
This question is commonly asked by the following companies: Amazon and Flipkart
Link to problem:
Intuition behind solution: save the initial state of the board by creating two hash sets to store both fresh oranges and rotten oranges. Iterate through the board populating both hash sets. Initialize your "minutes" to 0 and initialize a 2d integer array to represent the 4 cardinal directions (up, down, left, and right). While you have fresh oranges attempt to "infect" additional oranges by checking all rotten oranges you have and see if they have neighboring fresh oranges. Any time that they do, add that newly rotten orange to your "infected" hash set. Once you've run through all your rotten oranges you have available, if no new oranges became rotten (i.e. the size of infected is 0) return -1. Otherwise, continue your BFS by setting rotten = infected and incrementing the number of minutes elapsed by 1. Once your loop terminates return minutes.
MUSIC
----------------------------------------------------------------------------------------------------------------
xo bored llif3 by young frontwood
#techinterviews #leetcode #amazoninterview
0 Comments