Skip to content

Conversation

@yz4230
Copy link
Contributor

@yz4230 yz4230 commented Nov 19, 2025

Challenge 21 Solution

Submitted by: @yz4230
Challenge: Challenge 21

Description

This PR contains my solution for Challenge 21.

Changes

  • Added solution file to challenge-21/submissions/yz4230/solution-template.go

Testing

  • Solution passes all test cases
  • Code follows Go best practices

Thank you for reviewing my submission! 🚀

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 19, 2025

Walkthrough

This pull request adds a new Go file containing binary search implementations for challenge-21. The file includes iterative binary search, recursive binary search, and a function to find insertion positions in sorted arrays, along with a demonstration main function that tests these implementations.

Changes

Cohort / File(s) Summary
Binary Search Implementation
challenge-21/submissions/yz4230/solution-template.go
New file added with three binary search functions: BinarySearch (iterative), BinarySearchRecursive (recursive), and FindInsertPosition (insertion position finder), plus a test-driven main function.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify correctness of iterative and recursive binary search logic (boundary conditions, mid-point calculations)
  • Confirm FindInsertPosition correctly returns existing indices or proper insertion points
  • Review main function test cases for adequate coverage

Possibly related PRs

  • #747: Adds the identical file and functions (BinarySearch, BinarySearchRecursive, FindInsertPosition) to the same submission path
  • #714: Adds the same Go search utility functions in a different challenge-21 submission file
  • #707: Adds identical binary search functions with the same signatures in another solution-template Go file

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title directly summarizes the main change: adding a solution file for Challenge 21 by user yz4230, which aligns with the changeset.
Description check ✅ Passed The description is directly related to the changeset, explaining the Challenge 21 solution submission and listing the added file.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
challenge-21/submissions/yz4230/solution-template.go (1)

62-78: FindInsertPosition is correct; consider reducing duplication with BinarySearch

The insertion-index logic over [left, right) is correct for all targets (including before-first, after-last, and duplicates), and returning left on miss preserves sorted order. You could optionally factor the shared binary-search loop into a helper (e.g., a lower-bound function) and implement BinarySearch in terms of it to avoid duplicating nearly identical loops.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ca8ea29 and bf1bfdf.

📒 Files selected for processing (1)
  • challenge-21/submissions/yz4230/solution-template.go (1 hunks)
🔇 Additional comments (3)
challenge-21/submissions/yz4230/solution-template.go (3)

7-24: Sample main correctly exercises all search helpers

The demo covers both search variants and the insert-position helper with representative inputs; no functional issues here.


26-42: Iterative BinarySearch is correct and handles edge cases well

Logic over a half-open interval [left, right) with a safe mid calculation is sound, including for empty slices and out-of-range targets; it returns -1 exactly when not found.


44-60: Recursive BinarySearchRecursive implementation is logically sound

Closed-interval [left, right] handling with the left > right base case avoids out-of-bounds access and correctly terminates for all cases (including empty slices when called with right = len(arr)-1).

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