Skip to content

Conversation

@redstrike
Copy link
Contributor

Challenge 2 Solution

Submitted by: @redstrike
Challenge: Challenge 2

Description

This PR contains my solution for Challenge 2.

Changes

  • Added solution file to challenge-2/submissions/redstrike/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 Oct 18, 2025

Walkthrough

A new Go program is added in challenge-2/submissions/redstrike/ that implements a ReverseString function to reverse input strings using a rune-based two-pointer swap, with a main function that reads a line from standard input and prints the reversed result.

Changes

Cohort / File(s) Summary
Challenge 2 String Reversal Solution
challenge-2/submissions/redstrike/solution-template.go
Adds ReverseString(s string) string function that converts the input to runes, performs an in-place two-pointer swap to reverse them, and returns the reversed string. Main function reads a line from stdin and prints the reversed output.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • #560: Adds identical ReverseString exported function with matching main logic for Challenge 2.
  • #579: Implements the same ReverseString function with rune-slice two-pointer reversal and equivalent Challenge 2 main logic.
  • #572: Adds ReverseString with identical rune-based in-place reversal logic in a different Challenge 2 submission file.

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 pull request title "Add solution for Challenge 2 by redstrike" directly and clearly summarizes the main change in the changeset. The title accurately describes what was added—a solution file for Challenge 2 submitted by the user redstrike—and is concise without unnecessary noise. The title is specific enough that a teammate scanning commit history would immediately understand the primary purpose of this change.
Description Check ✅ Passed The pull request description is clearly related to the changeset and provides meaningful information about the submission. It identifies the solution as a Challenge 2 submission, explicitly references the added file location at challenge-2/submissions/redstrike/solution-template.go, and includes testing status information. The description is not vague or off-topic; it directly addresses what was changed and why, meeting the lenient criteria for this check.

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 (2)
challenge-2/submissions/redstrike/solution-template.go (2)

9-21: Consider checking for scanner errors.

After the scan loop, it's a Go best practice to check scanner.Err() to distinguish between EOF and actual read errors, though for this challenge context the current implementation is acceptable.

Optional improvement:

 func main() {
 	// Read input from standard input
 	scanner := bufio.NewScanner(os.Stdin)
 	if scanner.Scan() {
 		input := scanner.Text()
 
 		// Call the ReverseString function
 		output := ReverseString(input)
 
 		// Print the result
 		fmt.Println(output)
 	}
+	if err := scanner.Err(); err != nil {
+		fmt.Fprintf(os.Stderr, "Error reading input: %v\n", err)
+		os.Exit(1)
+	}
 }

23-38: Implementation is correct and handles Unicode properly.

The rune-based two-pointer reversal correctly handles multi-byte characters. As an optional improvement, Go's tuple assignment can simplify the swap.

Optional simplification:

 func ReverseString(s string) string {
     // Swap runes or two-pointer technique
 	runes := []rune(s) // Convert string to slice of runes
-	runesLen := len(runes)
-	halfRunesLen := runesLen / 2
+	n := len(runes)
 	
-	for i := 0; i < halfRunesLen; i++ {
-		r1 := runes[i]
-		r2 := runes[runesLen-1-i]
-		runes[i] = r2
-		runes[runesLen-1-i] = r1
+	for i := 0; i < n/2; i++ {
+		runes[i], runes[n-1-i] = runes[n-1-i], runes[i]
 	}
 	
 	return string(runes)
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1bda5b0 and f65bde0.

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

@RezaSi RezaSi merged commit 68dd639 into RezaSi:main Oct 19, 2025
5 checks passed
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.

2 participants