SShortSingh.
Back to feed

LeetCode Rotting Oranges Problem Solved Using Multi-Source BFS Approach

0
·1 views

The Rotting Oranges problem on LeetCode involves an m×n grid of fresh and rotten oranges, where every rotten orange spreads to adjacent fresh oranges each minute, and the goal is to find the minimum time to rot all oranges. A brute-force approach repeatedly scans the entire grid each minute, but this results in O((M×N)²) time complexity due to redundant cell visits. The optimal solution uses Multi-Source BFS, where all initially rotten oranges are pushed into a queue simultaneously at time zero and spread level by level. Each BFS level represents one minute, reducing time and space complexity to O(M×N). If any fresh oranges remain unreachable after BFS completes, the function returns -1 to indicate the task is impossible.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

React vs. Angular in 2026: Which Framework Suits Enterprise Architecture Best

As both React and Angular reach full maturity in 2026, the choice between them is less about quality and more about organizational fit. Angular's opinionated, standardized structure makes it well-suited for large enterprises with multiple distributed teams, offering built-in tools that reduce reliance on third-party libraries and lower security risks. React, by contrast, offers a lightweight and flexible approach that empowers senior developers to build highly customized, performance-tuned applications, though it requires strong technical leadership to avoid inconsistent codebases. Experts recommend that teams prioritize cross-team consistency and long-term maintainability should lean toward Angular, while those needing rapid UI iteration with disciplined developers may benefit more from React. Ultimately, the decision should be driven by team size, security requirements, and how much architectural freedom an organization can responsibly manage.

0
ProgrammingDEV Community ·

ContextVault 1.3 Offers Local-First Memory Engine to Unify AI Conversations and Sessions

ContextVault, a tool built by an independent developer, has reached version 1.3 and expanded from a simple browser conversation recorder into a local-first context engine for AI-assisted development. The tool addresses "context fragmentation," the problem of project knowledge becoming scattered across multiple AI platforms, coding agents, and terminal sessions. It operates across three layers: a Chrome extension that captures browser-based LLM conversations, a terminal integration, and a unified vault that makes all captured context searchable. All data is stored locally in IndexedDB with no backend server, no user account requirement, and no external data transmission. Conversations can be exported as Markdown files or ZIP archives, each tagged with metadata such as platform, model, and date.

0
ProgrammingDEV Community ·

Developer Builds Self-Hosted Scratchpad to Stop Losing Temporary Notes

Developer Sangeet Verma published a post on DEV Community on June 27 describing a self-hosted scratchpad tool he built. The project was created out of frustration with notes and jottings repeatedly disappearing. Verma developed the workspace using Go as the primary programming language. The tool is open source and falls under the web development category. The write-up is a roughly five-minute read tagged under selfhosted, Go, opensource, and webdev.

0
ProgrammingDEV Community ·

DataBench Offers 25+ Developer Utility Tools in One Free Browser-Based App

A developer has launched DataBench, a free, browser-based workbench that consolidates over 25 commonly used developer tools into a single tab. The platform includes utilities such as a JSON formatter, regex tester, CSV-to-SQL generator, Base64 encoder, and PDF compressor, among others. All tools run entirely client-side, meaning no data is sent to external servers. DataBench requires no sign-up, no installation, and has no paywall, making it immediately accessible at databench.app. The project is actively under development, with the creator inviting user feedback to expand the tool set further.

LeetCode Rotting Oranges Problem Solved Using Multi-Source BFS Approach · ShortSingh