Skip to content

Conversation

@hafizzz24498
Copy link

Submit coding challenge for backend developer from Hafiz Pangteh

@kengggg kengggg requested a review from Copilot June 20, 2025 02:59
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR submits solutions for two backend developer coding tasks and accompanying documentation.

  • Implement run-length encoding with Unicode surrogate pair support.
  • Fix thread-safety bug in BuggyCounter by using atomic operations.
  • Add solution notes in SOLUTIONS.md.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
tasks/01-run-length/csharp/Rle.cs Added Encode implementation handling surrogate pairs.
tasks/02-fix-the-bug/csharp/BuggyLib/BuggyCounter.cs Replaced manual increment + Thread.Sleep(0) with Interlocked.Increment.
SOLUTIONS.md Added solution notes and explanations for both tasks.

System.Threading.Thread.Sleep(0);
_current++;
return value;
return Interlocked.Increment(ref _current);
Copy link

Copilot AI Jun 20, 2025

Choose a reason for hiding this comment

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

Interlocked.Increment returns the incremented value, but the original code returned the previous value. If you need to preserve the original ID sequence starting from 0, consider returning Interlocked.Increment(ref _current) - 1 or adjust initialization/tests accordingly.

Suggested change
return Interlocked.Increment(ref _current);
return Interlocked.Increment(ref _current) - 1;

Copilot uses AI. Check for mistakes.
{
if (prevChar != "")
{
result.Append(prevChar + count);
Copy link

Copilot AI Jun 20, 2025

Choose a reason for hiding this comment

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

This concatenates strings and integers via +, causing an intermediate allocation. Consider using result.Append(prevChar).Append(count); to reduce allocations.

Suggested change
result.Append(prevChar + count);
result.Append(prevChar).Append(count);

Copilot uses AI. Check for mistakes.
}
if (prevChar != "")
{
result.Append(prevChar + count);
Copy link

Copilot AI Jun 20, 2025

Choose a reason for hiding this comment

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

Similar to above, replace with result.Append(prevChar).Append(count); to avoid creating an extra string.

Suggested change
result.Append(prevChar + count);
result.Append(prevChar).Append(count);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants