Skip to content

Conversation

@iamsurajmandal
Copy link
Contributor

Challenge 2 Solution

Submitted by: @iamsurajmandal
Challenge: Challenge 2

Description

This PR contains my solution for Challenge 2.

Changes

  • Added solution file to challenge-2/submissions/iamsurajmandal/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 Nov 7, 2025

Walkthrough

Adds a new Go solution file for challenge 2 containing a ReverseString exported function that reverses a Unicode string using rune-slice two-pointer swapping, along with a main function that reads input from standard input and prints the reversed result.

Changes

Cohort / File(s) Summary
Challenge 2 Solution
challenge-2/submissions/iamsurajmandal/solution-template.go
Introduces new file with exported ReverseString(s string) string function that reverses input by converting to runes and swapping via two-pointer technique, plus main function that reads stdin and prints reversed output

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify Unicode handling correctness in rune-slice reversal logic
  • Confirm input/output formatting matches expected behavior

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 'Add solution for Challenge 2 by iamsurajmandal' clearly and specifically describes the main change—adding a solution file for Challenge 2.
Description check ✅ Passed The description is directly related to the changeset, providing context about the Challenge 2 submission, the file location, and testing status.

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

🧹 Nitpick comments (1)
challenge-2/submissions/iamsurajmandal/solution-template.go (1)

26-30: Consider using idiomatic Go swap pattern.

The swap implementation is correct but can be simplified using Go's simultaneous assignment feature, which is more idiomatic and eliminates the need for a temporary variable.

Apply this diff for a more idiomatic swap:

 func ReverseString(s string) string {
-    runeString := []rune(s)
+	runeString := []rune(s)
-	for i, j := 0, len(runeString) - 1; i < j; i, j = i + 1, j - 1 {
-	    temp := runeString[i];
-	    runeString[i] = runeString[j]
-	    runeString[j] = temp
+	for i, j := 0, len(runeString)-1; i < j; i, j = i+1, j-1 {
+		runeString[i], runeString[j] = runeString[j], runeString[i]
 	}
 	return string(runeString)
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2b39f4a and fc64951.

📒 Files selected for processing (1)
  • challenge-2/submissions/iamsurajmandal/solution-template.go (1 hunks)
🔇 Additional comments (1)
challenge-2/submissions/iamsurajmandal/solution-template.go (1)

1-7: LGTM!

The package declaration and imports are appropriate for this solution.

Comment on lines +9 to +21
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)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add error handling for scanner.

The code doesn't check for scanner errors after reading input. If scanner.Scan() returns false, it could be due to EOF (expected) or an error (unexpected).

Apply this diff to add proper error handling:

 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)
+	}
 }
📝 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
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)
}
}
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)
}
}
🤖 Prompt for AI Agents
In challenge-2/submissions/iamsurajmandal/solution-template.go around lines 9 to
21, the main function calls scanner.Scan() but does not handle the case where
Scan returns false due to an error; update the code to always check
scanner.Err() after the Scan loop (or after the single Scan) and if err != nil
write a clear error message to stderr and exit non‑zero, while keeping normal
behavior for EOF/empty input (no error). Ensure you return/exit after reporting
the error so the program does not continue as if input succeeded.


// ReverseString returns the reversed string of s.
func ReverseString(s string) string {
runeString := []rune(s)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix indentation and remove unnecessary semicolon.

Lines 25 and 27 use spaces for indentation instead of tabs, and line 27 has an unnecessary semicolon. Go convention is to use tabs for indentation and avoid semicolons at the end of statements.

Run gofmt to automatically fix formatting:

gofmt -w challenge-2/submissions/iamsurajmandal/solution-template.go

Also applies to: 27-27

🤖 Prompt for AI Agents
challenge-2/submissions/iamsurajmandal/solution-template.go lines 25 and 27: the
indentation on these lines uses spaces instead of tabs and line 27 ends with an
unnecessary semicolon; fix by replacing the leading spaces with a single tab on
each affected line, remove the trailing semicolon from line 27, then run `gofmt
-w challenge-2/submissions/iamsurajmandal/solution-template.go` to apply Go
formatting conventions automatically.

@RezaSi RezaSi merged commit a76306a into RezaSi:main Nov 8, 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