Skip to content

Optimize N-Queens II using bitmasks - #284

Merged
Huerte merged 1 commit into
Huerte:mainfrom
Aaqibhafeezkhan:issue-274-nqueens-bitmask-v2
Nov 17, 2026
Merged

Huerte merged 1 commit into
Huerte:mainfrom
Aaqibhafeezkhan:issue-274-nqueens-bitmask-v2

Conversation

@Aaqibhafeezkhan

Copy link
Copy Markdown
Contributor

Summary

Optimizes the existing N-Queens II solution using integer bitmasks.

Changes

  • Adds solutions/python/practice1_v2.py.
  • Replaces repeated board scanning with column and diagonal bitmasks.
  • Uses lowest-set-bit extraction to explore available positions.
  • Eliminates the need for an N × N board.
  • Preserves the original implementation.

Validation

  • Verified known N-Queens counts for board sizes 0 through 14.
  • Added negative-input validation.
  • All expected-result assertions pass.

Closes #274

@Aaqibhafeezkhan Aaqibhafeezkhan left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Original implementation untouched.
  • Optimized implementation added separately.
  • Correct diagonal-mask propagation.
  • No unnecessary board allocation.
  • Known N-Queens results verified.
  • Issue requirements addressed.
  • Single focused commit.

@Huerte
Huerte merged commit e4d0221 into Huerte:main Nov 17, 2026
1 check failed
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.

Challenge: make an existing solution shorter or faster (30 min)

2 participants