Skip to content

Add solution for Challenge 2 by gootibi - #1980

Open
gootibi wants to merge 1 commit into
RezaSi:mainfrom
gootibi:challenge-2-gootibi
Open

gootibi wants to merge 1 commit into
RezaSi:mainfrom
gootibi:challenge-2-gootibi

Conversation

@gootibi

@gootibi gootibi commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Challenge 2 Solution

Submitted by: @gootibi
Challenge: Challenge 2

Description

This PR contains my solution for Challenge 2.

Changes

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

Testing

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

Thank you for reviewing my submission! 🚀

@coderabbitai

coderabbitai Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The PR adds a Go command-line solution that reads one line, reverses it with ReverseString, and prints the result. The implementation handles ASCII correctly but mishandles multi-byte UTF-8 characters.

Changes

String reversal solution

Layer / File(s) Summary
ReverseString implementation
challenge-2/submissions/gootibi/solution-template.go
Adds ReverseString, which constructs a reversed string using rune length and byte-based indexing.
Command-line input and output
challenge-2/submissions/gootibi/solution-template.go
Adds main, which scans standard input, calls ReverseString, and prints the result.

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

Merge Risk: 🟡 Moderate · up to 1a464

This solution can produce incorrect output for multi-byte UTF-8 input because it counts characters but indexes the string by bytes; merge should wait for this bug to be corrected.

Possibly related PRs

Poem

A rabbit reads a line with care,
Then flips its letters through the air.
ASCII hops from left to right,
UTF-8 needs a gentler bite.
The result prints neat and bright.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the addition of gootibi's Challenge 2 solution.
Description check ✅ Passed The description explains that the pull request adds gootibi's Challenge 2 solution file.
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.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

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.

Warning

⚠️ This pull request shows signs of AI-generated slop (redundant_comments). It has been flagged by CodeRabbit slop detection and should be reviewed carefully.

@gootibi

gootibi commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Challenge 2 Solution

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 13bcd88c-4127-428b-b90b-3a61017f4887

📥 Commits

Reviewing files that changed from the base of the PR and between 41c16a8 and 1a4642d.

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

Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review.

Comment on lines +29 to +31
for i := len(runes) - 1; i > -1; i-- {
output = append(output, string(s[i]))
}

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

file="challenge-2/submissions/gootibi/solution-template.go"

if rg -n 'output = append\(output, string\(s\[i\]\)\)' "$file"; then
  echo "ReverseString still indexes bytes instead of runes." >&2
  exit 1
fi

rg -n 'output = append\(output, string\(runes\[i\]\)\)' "$file"

Repository: RezaSi/go-interview-practice

Length of output: 261


🏁 Script executed:

#!/bin/bash
set -euo pipefail

file="challenge-2/submissions/gootibi/solution-template.go"
cat -n "$file" | sed -n '1,80p'

python3 - <<'PY'
def candidate(s):
    runes = list(s)
    output = []
    # Model Go's s[i] byte indexing and string(byte) conversion.
    data = s.encode("utf-8")
    for i in range(len(runes) - 1, -1, -1):
        output.append(bytes([data[i]]).decode("utf-8", errors="replace"))
    return "".join(output)

def rune_indexed(s):
    runes = list(s)
    return "".join(runes[i] for i in range(len(runes) - 1, -1, -1))

for value in ("abc", "hé", "世界", "🙂a"):
    print(repr(value), "candidate=", repr(candidate(value)), "expected=", repr(rune_indexed(value)))
PY

Repository: RezaSi/go-interview-practice

Length of output: 1142


Index runes instead of s.

len(runes) counts Unicode code points, but s[i] reads bytes. Multi-byte UTF-8 input produces invalid output. Use runes[i] to preserve each character.

This branch has not been deployed

No deployments
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