Skip to content

Add solution for Challenge 21 by alimkinpark - #1640

Open
alimkinpark wants to merge 1 commit into
RezaSi:mainfrom
alimkinpark:challenge-21-alimkinpark
Open

Add solution for Challenge 21 by alimkinpark#1640
alimkinpark wants to merge 1 commit into
RezaSi:mainfrom
alimkinpark:challenge-21-alimkinpark

Conversation

@alimkinpark

Copy link
Copy Markdown
Contributor

Challenge 21 Solution

Submitted by: @alimkinpark
Challenge: Challenge 21

Description

This PR contains my solution for Challenge 21.

Changes

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

Testing

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

Thank you for reviewing my submission! 🚀

@coderabbitai

coderabbitai Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

A new Go solution file is added containing three binary search implementations (iterative, recursive, and insertion-position finding) along with a main() test harness that demonstrates their usage on sample data.

Changes

Cohort / File(s) Summary
Binary Search Implementation
challenge-21/submissions/alimkinpark/solution-template.go
Introduces BinarySearch() for iterative binary search, BinarySearchRecursive() for recursive implementation, and FindInsertPosition() to locate insertion indices; includes a main() function demonstrating all three functions with example values.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 Hops through sorted arrays with glee,
Binary bounds grow wild and free,
Left and right dance, searching well,
Insert positions? Rabbit can tell!
Recursion bounces, left then right,
Challenge twenty-one shines bright!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a solution for Challenge 21 by a specific contributor.
Description check ✅ Passed The description is directly related to the changeset, clearly identifying the challenge being solved and the file being added.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.11.4)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


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
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7b4003b7-5be3-47b2-827f-aba043b6eabb

📥 Commits

Reviewing files that changed from the base of the PR and between bf844ae and b91e5b2.

📒 Files selected for processing (1)
  • challenge-21/submissions/alimkinpark/solution-template.go

Comment on lines +64 to +67
if arr[mid] < target {
return BinarySearchRecursive(arr, target, left + 1, right)
} else {
return BinarySearchRecursive(arr, target, left, right - 1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use mid to shrink recursive bounds.

At Line 65 and Line 67, the recursion updates with left + 1 / right - 1 instead of mid + 1 / mid - 1. This breaks binary-search narrowing, increases recursion depth, and can cause stack pressure on large inputs.

Suggested fix
-	if arr[mid] < target {
-	    return BinarySearchRecursive(arr, target, left + 1, right)
-	} else {
-	    return BinarySearchRecursive(arr, target, left, right - 1)
-	}
+	if arr[mid] < target {
+	    return BinarySearchRecursive(arr, target, mid+1, right)
+	}
+	return BinarySearchRecursive(arr, target, left, mid-1)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if arr[mid] < target {
return BinarySearchRecursive(arr, target, left + 1, right)
} else {
return BinarySearchRecursive(arr, target, left, right - 1)
if arr[mid] < target {
return BinarySearchRecursive(arr, target, mid+1, right)
}
return BinarySearchRecursive(arr, target, left, mid-1)

@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown

⚠️ Auto-merge failed

Could not automatically merge this PR: Resource not accessible by integration

A maintainer will need to merge manually.

1 similar comment
@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown

⚠️ Auto-merge failed

Could not automatically merge this PR: Resource not accessible by integration

A maintainer will need to merge manually.

@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown

👋 Action needed for auto-merge

This PR cannot be auto-merged because "Allow edits from maintainers" is enabled. This is a GitHub limitation with automated workflows.

To fix: Please uncheck "Allow edits from maintainers" in the PR sidebar (under the reviewers section), and the PR will be auto-merged in the next cycle.

Alternatively, a maintainer can merge this manually.

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