Skip to content

Conversation

@macborowy
Copy link
Contributor

Challenge 2 Solution

Submitted by: @macborowy
Challenge: Challenge 2

Description

This PR contains my solution for Challenge 2.

Changes

  • Added solution file to challenge-2/submissions/macborowy/solution-template.go

Testing

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

Thank you for reviewing my submission! 🚀

@coderabbitai
Copy link

coderabbitai bot commented Oct 12, 2025

Walkthrough

Adds a Go CLI program that reads a line from stdin, reverses it via a new ReverseString function, and prints the result.

Changes

Cohort / File(s) Summary
String reversal CLI
challenge-2/submissions/macborowy/solution-template.go
New main program using bufio.Scanner to read stdin, ReverseString(s string) to reverse the input via byte indexing, and fmt.Println to output the reversed string.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Pre-merge checks

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly and concisely summarizes the main change by indicating that the author is adding their solution for Challenge 2, directly reflecting the primary purpose of the pull request without unnecessary details or noise.
Description Check ✅ Passed The description directly relates to the addition of the solution file for Challenge 2, outlines what was changed and how it was tested, and therefore accurately reflects the content of the changeset.

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

@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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a2868df and 82f8023.

📒 Files selected for processing (1)
  • challenge-2/submissions/macborowy/solution-template.go (1 hunks)

Comment on lines +24 to +33
func ReverseString(s string) string {
l := len(s)
a := make([]byte, l, l)

for i := len(s) - 1; i >= 0; i-- {
a[l-1-i] = s[i]
}

return string(a)
} No newline at end of file
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Handle UTF-8 runes, not raw bytes.

Reversing by byte corrupts any multi-byte characters (e.g., "こんにちは" becomes invalid UTF-8). Convert to runes before reversing and rebuild the string.

Apply this diff:

-func ReverseString(s string) string {
-	l := len(s)
-	a := make([]byte, l, l)
-
-	for i := len(s) - 1; i >= 0; i-- {
-		a[l-1-i] = s[i]
-	}
-
-	return string(a)
-}
+func ReverseString(s string) string {
+	runes := []rune(s)
+	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
+		runes[i], runes[j] = runes[j], runes[i]
+	}
+	return string(runes)
+}
🤖 Prompt for AI Agents
In challenge-2/submissions/macborowy/solution-template.go around lines 24 to 33,
the function reverses raw bytes which corrupts multi-byte UTF-8 characters;
convert the input string to a slice of runes, reverse that rune slice (swap rune
positions from ends toward center) and then return a new string from the
reversed rune slice so multi-byte characters are preserved.

@macborowy macborowy closed this Oct 12, 2025
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