Skip to content

Done Backtracking-3#1087

Open
sainathek1999 wants to merge 1 commit intosuper30admin:masterfrom
sainathek1999:master
Open

Done Backtracking-3#1087
sainathek1999 wants to merge 1 commit intosuper30admin:masterfrom
sainathek1999:master

Conversation

@sainathek1999
Copy link
Copy Markdown

No description provided.

@super30admin
Copy link
Copy Markdown
Owner

N-Queens (problem1.java)

It appears you have submitted a solution for the "Word Search" problem instead of the "N-Queens" problem. Please review the problem statement carefully and ensure your code addresses the correct problem. For the N-Queens problem, you need to generate all distinct configurations of placing n queens on an n x n chessboard such that no two queens attack each other.

To solve N-Queens, you should consider using backtracking. Here are some tips:

  • Represent the board as a 2D array or use a more efficient representation (like tracking queen positions in an array).
  • For each row, try placing a queen in each column and check if it is valid (no conflicts with previously placed queens).
  • The validation function should check for attacks in the same column, and both diagonals (upper-left and upper-right).
  • When you reach the last row, you have found a solution. Convert the board to the required output format (list of strings).

Your Word Search solution is well-written, but it is crucial to solve the correct problem. Double-check the problem title and description before coding.

VERDICT: NEEDS_IMPROVEMENT


Word Search (problem2.java)

It seems you have submitted a solution for the N-Queens problem instead of the Word Search problem. Please double-check the problem statement and your code. For the Word Search problem, you need to implement a backtracking DFS that traverses the grid to find the given word. You should start by iterating over each cell in the grid and then perform a DFS from that cell if it matches the first character of the word. During DFS, you need to mark visited cells (e.g., by changing them to a special character) and then backtrack by restoring the original value.

Here is a suggested approach for Word Search:

  1. Iterate over every cell (i, j) in the grid.
  2. For each cell, if the character matches the first character of the word, call a DFS function.
  3. In the DFS function, check if the current index equals the word length -> return true.
  4. Check boundaries and if the current cell is visited or doesn't match -> return false.
  5. Mark the current cell as visited (e.g., by setting it to '#').
  6. Recursively check all four directions (up, down, left, right) for the next character.
  7. Backtrack by restoring the original value in the cell.
  8. If any DFS call returns true, return true. Otherwise, after all cells are tried, return false.

Your current code for N-Queens is well-written and correct for that problem, but it does not address Word Search. Please reimplement for the correct problem.

VERDICT: NEEDS_IMPROVEMENT

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.

2 participants