Skip to content

Create Car-Fleet-II.java #505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Create Car-Fleet-II.java #505

wants to merge 1 commit into from

Conversation

sp995
Copy link

@sp995 sp995 commented May 31, 2025

Pull Request Template

Description

This PR adds a solution for the problem "419. Battleships in a Board" from LeetCode.
The goal is to count the number of battleships present on a given 2D board without modifying the board or using extra space.

Approach:

We iterate through each cell in the board. For a cell containing 'X', we check if it is the top-left-most part of a new battleship by ensuring there's no 'X' directly above or to the left. If these conditions hold, we increment the battleship count.

Dependencies:

No external dependencies are required for this change.


Put check marks:

Have you made changes in README file?

  • Added problem & solution under correct topic.
  • Specified Space & Time complexity.
  • Specified difficulty level, tag & Note(if any).

How Has This Been Tested?

The solution has been tested using a sample input and produces the correct number of battleships.

  • Test A: Sample board with two battleships
  • Test B

Make sure all below guidelines are followed else PR will get Rejected:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code so that it is easy to understand
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant