Rotting Oranges (LeetCode 994) | Full solution using DFS | Flood Fill algorithm

Nikhil Lohia โ€ข March 5, 2025
Video Thumbnail
Nikhil Lohia Logo

Nikhil Lohia

View Channel

About

I want to share with you my knowledge, that I have gained all my life. I like to see every task in your day to day life as an interesting problem to solve, and if you can understand the requirements, solving for it can become somewhat intuitive. I try to explore certain aspects of day to day life and how I can make them easier for you. This involves daily hacks, tutorials, innovations, new discoveries, experiences and all the stuff I find amusing. As a software engineer myself, I also believe that good problem solving skills can help you overcome most of the barriers in life. Programming is one of them. If you know how to approach a problem, writing a code for it in any language could be a very typical task. With this channel I aim to focus on the way to solve a problem efficiently rather than just its implementation.

Video Description

Join this channel to get access to perks: https://www.youtube.com/channel/UCT-S2ngqEBoYCM5UKuNeELg/join Actual problem on LeetCode: https://leetcode.com/problems/rotting-oranges/description/ Chapters: 00:00 - Intro 00:53 - Problem Statement 02:21 - Understanding Visually 06:51 - What roadblocks? 09:27 - Approach multiple rotting oranges 17:04 - Dry run of Code 21:01 - Final Thoughts ๐Ÿ“š Links to topics I talk about in the video: Number of Islands: https://youtu.be/ZgCZfXPo3hI Depth First Search: https://youtu.be/bOrCi635kUw Breadth First Search: https://youtu.be/zfwHQNqszP4 Other Medium Problems: https://www.youtube.com/playlist?list=PLFdAYMIVJQHO1paovM-tu2vtGzQU72z_U ๐Ÿ“˜ A text based explanation is available at: https://studyalgorithms.com Code on Github: https://github.com/nikoo28/java-solutions/blob/master/src/main/java/leetcode/medium/RottingOranges.java Test-cases on Github: https://github.com/nikoo28/java-solutions/blob/master/src/test/java/leetcode/medium/RottingOrangesTest.java ๐Ÿ“– Reference Books: Starting Learn to Code: https://amzn.to/3sJm8Wl Favorite book to understand algorithms: https://amzn.to/4848xJH Favorite book for data structures: https://amzn.to/3P96YBv Get started for interview preparation: https://amzn.to/44Nn5du ๐Ÿ”— To see more videos like this, you can show your support on: https://www.buymeacoffee.com/studyalgorithms ๐ŸŽฅ My Recording Gear: Recording Light: https://amzn.to/3PdsViT Microphone: https://amzn.to/3Exv83x Recording Camera: https://amzn.to/3PwyN8e Tablet to sketch and draw: https://amzn.to/3ZdKVy7 Sketching Tool: https://amzn.to/45XJEgY Laptop to edit videos: https://amzn.to/460ofDu ๐Ÿ’ป Get Social ๐Ÿ’ป Follow on Facebook at: https://www.facebook.com/studyalgos Subscribe to RSS feeds: https://studyalgorithms.com/feed/ Join fan mail: http://eepurl.com/g9Dadv #leetcode #programming #interview

You May Also Like

Coding Practice Must-Haves

AI-recommended products based on this video

Loading...
Laptop Sleeve Case 11โ€“14 Inch MacBook Air MacBook Pro Surface Laptop Dell XPS 13 HP Envy Pavilion Lenovo Yoga Slim IdeaPad Acer Swift Chromebook Samsung Galaxy Book Shockproof Leather Bag Colour Blue

Laptop Sleeve Case 11โ€“14 Inch MacBook Air MacBook Pro Surface Laptop Dell XPS 13 HP Envy Pavilion Lenovo Yoga Slim IdeaPad Acer Swift Chromebook Samsung Galaxy Book Shockproof Leather Bag Colour Blue

(98)
$81.45
Loading...
Gumdrop ProTech Case for Dell New XPS 13 Plus 9320 Laptop- Slim Lightweight Case with Energy Displacement Protection, Non-Skid Rubber Feet and Frosted Exterior for Bumps and Drops (Black)

Gumdrop ProTech Case for Dell New XPS 13 Plus 9320 Laptop- Slim Lightweight Case with Energy Displacement Protection, Non-Skid Rubber Feet and Frosted Exterior for Bumps and Drops (Black)

(49)
$109.43$108.34
FREE delivery Aug 11 - 13
Loading...
65W 45W USB C Laptop Charger Compatible with Dell Latitude 5420 5430 5520 5530 7340 7430 Inspiron 14 16 XPS 13 Chromebook 3100 Dell Computer Type C Fast Charging AC Adapter Power Cord

65W 45W USB C Laptop Charger Compatible with Dell Latitude 5420 5430 5520 5530 7340 7430 Inspiron 14 16 XPS 13 Chromebook 3100 Dell Computer Type C Fast Charging AC Adapter Power Cord

(7)
$19.99
FREE delivery Sun, Aug 24 on your first order
Loading...
Charger for Dell Computer Inspiron XPS Laptop 65W 45W Power Supply AC Adapter for Dell-Inspiron 15-3000 15-5000 15-7000 11-3000 13-5000 13-7000 17-5000 XPS 13 Series 5559 5558 5755 5758 Laptop Charger

Charger for Dell Computer Inspiron XPS Laptop 65W 45W Power Supply AC Adapter for Dell-Inspiron 15-3000 15-5000 15-7000 11-3000 13-5000 13-7000 17-5000 XPS 13 Series 5559 5558 5755 5758 Laptop Charger

(621)
$21.99
FREE delivery Sun, Aug 24 on your first order
100+ bought in past month
Loading...
Dell UltraSharp 24 Monitor - U2424H

Dell UltraSharp 24 Monitor - U2424H

(43)
$309.44$262.14
FREE delivery Aug 22 - 25Only 8 left in stock.
Loading...
Dell UltraSharp U2723QE 27" 4K UHD WLED LCD Monitor - 16:9 - Black, Silver EPEAT

Dell UltraSharp U2723QE 27" 4K UHD WLED LCD Monitor - 16:9 - Black, Silver EPEAT

(13)
$699.99$650.99
FREE delivery Tue, Oct 7
50+ bought in past month
Loading...
Dell UltraSharp U2725QE 27' 4K Thunderbolt-Hub-Monitor mit Bildwiederholfrequenz Von 120Hz

Dell UltraSharp U2725QE 27' 4K Thunderbolt-Hub-Monitor mit Bildwiederholfrequenz Von 120Hz

(50)
$1,059.91
FREE delivery Oct 7 - 8
Loading...
Logitech G305 LIGHTSPEED Wireless Gaming Mouse, Hero 12K Sensor, 12,000 DPI, Lightweight, 6 Programmable Buttons, 250h Battery Life, On-Board Memory, PC/Mac - Black

Logitech G305 LIGHTSPEED Wireless Gaming Mouse, Hero 12K Sensor, 12,000 DPI, Lightweight, 6 Programmable Buttons, 250h Battery Life, On-Board Memory, PC/Mac - Black

(21,223)
$44.98
FREE delivery Tue, Oct 14
1K+ bought in past month
Loading...
Logitech M185 Wireless Mouse, 2.4GHz with USB Mini Receiver, 12-Month Battery Life, 1000 DPI Optical Tracking, Ambidextrous, Compatible with PC, Mac, Laptop - Black

Logitech M185 Wireless Mouse, 2.4GHz with USB Mini Receiver, 12-Month Battery Life, 1000 DPI Optical Tracking, Ambidextrous, Compatible with PC, Mac, Laptop - Black

(43,809)
$14.99$11.99
FREE delivery Mon, Sep 22 on your first order
1K+ bought in past month
Loading...
Logitech G203 Wired Gaming Mouse, 8,000 DPI, Rainbow Optical Effect LIGHTSYNC RGB, 6 Programmable Buttons, On-Board Memory, Screen Mapping, PC/Mac Computer and Laptop Compatible - Black
Best Seller

Logitech G203 Wired Gaming Mouse, 8,000 DPI, Rainbow Optical Effect LIGHTSYNC RGB, 6 Programmable Buttons, On-Board Memory, Screen Mapping, PC/Mac Computer and Laptop Compatible - Black

(17,871)
$27.98$22.38
FREE delivery Tue, Oct 14 on your first order
500+ bought in past month
Loading...
Logitech G435 Lightspeed and Bluetooth Wireless Gaming Headset - Lightweight Over-Ear Headphones, Built-in mics, 18h Battery, Compatible with Dolby Atmos, PC, Mobile - Black

Logitech G435 Lightspeed and Bluetooth Wireless Gaming Headset - Lightweight Over-Ear Headphones, Built-in mics, 18h Battery, Compatible with Dolby Atmos, PC, Mobile - Black

(14,873)
$49.99$39.99
FREE delivery Thu, Aug 21
400+ bought in past month
Loading...
CORSAIR iCUE Link XD5 RGB Elite LCD Pump-Reservoir Unit - D5 PWM Pump - 480x480 IPS LCD Screen - 22 Addressable RGB LEDs - 440ml Nylon Reservoir - White

CORSAIR iCUE Link XD5 RGB Elite LCD Pump-Reservoir Unit - D5 PWM Pump - 480x480 IPS LCD Screen - 22 Addressable RGB LEDs - 440ml Nylon Reservoir - White

(17)
$379.99
FREE delivery Sun, Aug 24
Loading...
CORSAIR iCUE Link XC7 RGB Elite CPU Water Block - Transparent Flow Chamber - 24 RGB LEDs - Fits Intelยฎ LGA 1700, AMDยฎ AM5 and Older - White

CORSAIR iCUE Link XC7 RGB Elite CPU Water Block - Transparent Flow Chamber - 24 RGB LEDs - Fits Intelยฎ LGA 1700, AMDยฎ AM5 and Older - White

(56)
$149.99$125.33
FREE delivery Sun, Aug 24
Loading...
CORSAIR Hydro X Series iCUE Link XH405i Custom Cooling Kit โ€“ Hardline Water Cooling Loop โ€“ XC7 Elite CPU Water Block โ€“ XD5 Elite D5 Pump Res โ€“ XR5 360mm Radiator โ€“ 3X QX120 RGB Fans

CORSAIR Hydro X Series iCUE Link XH405i Custom Cooling Kit โ€“ Hardline Water Cooling Loop โ€“ XC7 Elite CPU Water Block โ€“ XD5 Elite D5 Pump Res โ€“ XR5 360mm Radiator โ€“ 3X QX120 RGB Fans

(235)
$879.99
FREE delivery Sun, Aug 24
Loading...
Amazon Basics Clear Thermal Laminating Plastic Paper Laminator Sheets, 9 x 11.5-Inch, 200-Pack, 3mil

Amazon Basics Clear Thermal Laminating Plastic Paper Laminator Sheets, 9 x 11.5-Inch, 200-Pack, 3mil

(87,803)
$25.99$19.49
FREE delivery Mon, Sep 15 on your first order
10K+ bought in past month
Loading...
Amazon Basics 9 Volt Everyday Alkaline Battery - Pack of 8 The Nordic Swan Ecolabel

Amazon Basics 9 Volt Everyday Alkaline Battery - Pack of 8 The Nordic Swan Ecolabel

(215,650)
$12.78
FREE delivery Wed, Aug 20 on your first order
4K+ bought in past month
Loading...
Amazon Basics 48 Pack AA High-Performance Alkaline Batteries, 10-Year Shelf Life, Easy to Open Value Pack The Nordic Swan Ecolabel

Amazon Basics 48 Pack AA High-Performance Alkaline Batteries, 10-Year Shelf Life, Easy to Open Value Pack The Nordic Swan Ecolabel

(568,836)
$18.26
FREE delivery Wed, Aug 20 on your first order
10K+ bought in past month
Loading...
Amazon Basics 64GB microSDXC Memory Card with Full Size Adapter, 100MB/s, U3, 2-Pack

Amazon Basics 64GB microSDXC Memory Card with Full Size Adapter, 100MB/s, U3, 2-Pack

(18,727)
$21.99$20.39
FREE delivery Sun, Aug 10 on your first order
500+ bought in past month
Loading...
NEEWER Advanced 18 inch LED Ring Light for Phone, LCD Touch Screen, 2.4G Remote Lights Control, 3200-5600K, Tripod Light for iPhone Action Camera, for Studio Makeup TikTok YouTube Video Salon (Black)

NEEWER Advanced 18 inch LED Ring Light for Phone, LCD Touch Screen, 2.4G Remote Lights Control, 3200-5600K, Tripod Light for iPhone Action Camera, for Studio Makeup TikTok YouTube Video Salon (Black)

(2,807)
$181.49
FREE delivery Sun, Aug 10
Loading...
Razer BlackShark V2 X Gaming Headset: 50mm Drivers - Cardioid Mic - Memory Foam Cushion - Lightweight- Comfortable, Noise Isolating Earcups - for PC, PS4, PS5, Switch - 3.5mm Audio Jack - Black ECOLOGO

Razer BlackShark V2 X Gaming Headset: 50mm Drivers - Cardioid Mic - Memory Foam Cushion - Lightweight- Comfortable, Noise Isolating Earcups - for PC, PS4, PS5, Switch - 3.5mm Audio Jack - Black ECOLOGO

(16,830)
$47.98$38.38
FREE delivery Sat, Nov 15
1K+ bought in past month
Loading...
12V/24V 100W Car Laptop Charger USB C for Lenovo Thinkpad MacBook HP Dell Acer Asus,Google,MSI, LG, Samsung,Huawei,Surface pro 9 8, Razer, Chromebook, ROG Ally, Steam Deck and All Type-C Devices

12V/24V 100W Car Laptop Charger USB C for Lenovo Thinkpad MacBook HP Dell Acer Asus,Google,MSI, LG, Samsung,Huawei,Surface pro 9 8, Razer, Chromebook, ROG Ally, Steam Deck and All Type-C Devices

(6)
$29.99
FREE delivery Tue, Jun 17 on your first order
50+ bought in past month
Loading...
Razer Universal Quick Charging Stand for Xbox Series X|S: Magnetic Secure Charging - Matches Forza Horizon 5 Limited Edition Xbox Wireless Controller - USB Powered - (Controller Sold Separately)

Razer Universal Quick Charging Stand for Xbox Series X|S: Magnetic Secure Charging - Matches Forza Horizon 5 Limited Edition Xbox Wireless Controller - USB Powered - (Controller Sold Separately)

(1,103)
$52.27$33.70
PrimeFREE delivery Sat, Jun 14