Skip to content

Add solution for Challenge 17 by atplay90#1900

Open
atplay90 wants to merge 1 commit into
RezaSi:mainfrom
atplay90:challenge-17-atplay90
Open

Add solution for Challenge 17 by atplay90#1900
atplay90 wants to merge 1 commit into
RezaSi:mainfrom
atplay90:challenge-17-atplay90

Conversation

@atplay90

Copy link
Copy Markdown
Contributor

Challenge 17 Solution

Submitted by: @atplay90
Challenge: Challenge 17

Description

This PR contains my solution for Challenge 17.

Changes

  • Added solution file to challenge-17/submissions/atplay90/solution-template.go

Testing

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

Thank you for reviewing my submission! 🚀

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds a Go command-line palindrome checker with input cleaning, case normalization, two-pointer comparison, and exported IsPalindrome functionality.

Changes

Palindrome feature

Layer / File(s) Summary
Normalization and palindrome checking
challenge-17/submissions/atplay90/solution-template.go
Input is filtered to ASCII letters and digits, converted to lowercase, and checked for symmetry using comparisons from both ends.
Command-line integration
challenge-17/submissions/atplay90/solution-template.go
The program reads standard input, calls IsPalindrome, and prints whether the input is a palindrome.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Poem

A bunny found a word to scan,
Cleaned its marks as best it can.
From both ends, the letters meet,
Mirrored hops make checks complete.
“Palindrome!” the rabbit sings,
And wiggles both its ears and wings.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding a solution for Challenge 17.
Description check ✅ Passed The description matches the submission and change details for Challenge 17.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

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.12.2)

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

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

@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.

🧹 Nitpick comments (1)
challenge-17/submissions/atplay90/solution-template.go (1)

23-47: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Consider an in-place two-pointer approach to optimize space complexity.

The current approach allocates new strings when filtering out non-alphanumeric characters and converting to lowercase, resulting in O(N) space complexity. You can optimize this to O(1) space complexity by using a two-pointer approach that evaluates characters from both ends in-place.

(Note: Applying this refactor will make the "strings" import unused, so remember to remove it to prevent a compilation error.)

♻️ Proposed refactor for O(1) space complexity
-func removeNonAlphanumeric(s string) string {
-    var result strings.Builder
-    for _, r := range s {
-        if (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') {
-            result.WriteRune(r)
-        }
-    }
-    return result.String()
-}
-
 // 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 {
-	
-	// 1. Clean the string (remove spaces, punctuation, and convert to lowercase)
-	s = removeNonAlphanumeric(s)
-	s = strings.ToLower(s)
-	// 2. Check if the cleaned string is the same forwards and backwards
-	for i := 0; i < len(s)/2; i++ {
-        if s[i] != s[len(s)-1-i] {
-            return false
-        }
-    }
-	return true
+	for i, j := 0, len(s)-1; i < j; {
+		if !isAlphanumeric(s[i]) {
+			i++
+			continue
+		}
+		if !isAlphanumeric(s[j]) {
+			j--
+			continue
+		}
+		if toLower(s[i]) != toLower(s[j]) {
+			return false
+		}
+		i++
+		j--
+	}
+	return true
+}
+
+func isAlphanumeric(c byte) bool {
+	return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')
+}
+
+func toLower(c byte) byte {
+	if c >= 'A' && c <= 'Z' {
+		return c + 'a' - 'A'
+	}
+	return c
 }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3b2c9261-fe36-4cb1-93e9-0d67cbdd39be

📥 Commits

Reviewing files that changed from the base of the PR and between 7fdf514 and 80924fc.

📒 Files selected for processing (1)
  • challenge-17/submissions/atplay90/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