Skip to content

Add solution for Challenge 17 by shansing#1437

Open
shansing wants to merge 2 commits intoRezaSi:mainfrom
shansing:challenge-17-shansing
Open

Add solution for Challenge 17 by shansing#1437
shansing wants to merge 2 commits intoRezaSi:mainfrom
shansing:challenge-17-shansing

Conversation

@shansing
Copy link
Contributor

Challenge 17 Solution

Submitted by: @shansing
Challenge: Challenge 17

Description

This PR contains my solution for Challenge 17.

Changes

  • Added solution file to challenge-17/submissions/shansing/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 Feb 26, 2026

Walkthrough

Adds a new Go solution file implementing a palindrome checker. The solution includes an exported IsPalindrome function that normalizes input by converting to lowercase and removing non-alphanumeric characters, then validates palindromes using two-pointer comparison from both ends.

Changes

Cohort / File(s) Summary
Palindrome Checker Solution
challenge-17/submissions/shansing/solution-template.go
New file adding IsPalindrome(s string) bool function that normalizes input via regex-based alphanumeric filtering and performs two-pointer palindrome validation. Includes main entry point for user interaction via standard input/output.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 A palindrome checker hops into place,
Cleaning letters with regex grace,
Two pointers compare from end to start,
Racing toward truth with algorithmic heart! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add solution for Challenge 17 by shansing' directly describes the main change: adding a solution file for Challenge 17, which matches the changeset.
Description check ✅ Passed The description is related to the changeset, providing context about Challenge 17 submission, the file added, and testing claims, though details about the palindrome checker implementation are minimal.

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


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: 1

🧹 Nitpick comments (2)
challenge-17/submissions/shansing/solution-template.go (2)

27-27: Simplify empty check: len(s) <= 0len(s) == 0.

len() never returns a negative value, so <= 0 is redundant.

-	if len(s) <= 0 {
+	if len(s) == 0 {

31-31: Compile regex once at package level to avoid repeated compilation.

regexp.MustCompile is called on every invocation of IsPalindrome, which adds unnecessary overhead. Hoisting it to a package-level variable compiles it once at init time.

Suggested fix
+var nonAlphanumericRegex = regexp.MustCompile("[^a-z0-9]+")
+
 // IsPalindrome checks if a string is a palindrome.
 // A palindrome reads the same backward as forward, ignoring case, spaces, and punctuation.
 func IsPalindrome(s string) bool {
 	if len(s) <= 0 {
 		return true
 	}
 	// 1. Clean the string (remove spaces, punctuation, and convert to lowercase)
-	cleaned := regexp.MustCompile("[^a-z0-9]+").ReplaceAllString(strings.ToLower(s), "")
+	cleaned := nonAlphanumericRegex.ReplaceAllString(strings.ToLower(s), "")
 	// 2. Check if the cleaned string is the same forwards and backwards

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a7ac764 and 0f8202e.

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

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