Skip to content

Add solutions for Challenges 1-7 by shahzodshafizod#1466

Merged
RezaSi merged 8 commits intoRezaSi:mainfrom
shahzodshafizod:shahzodshafizod
Mar 16, 2026
Merged

Add solutions for Challenges 1-7 by shahzodshafizod#1466
RezaSi merged 8 commits intoRezaSi:mainfrom
shahzodshafizod:shahzodshafizod

Conversation

@shahzodshafizod
Copy link
Contributor

No description provided.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 28, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds four new Go solutions: an integer Sum with overflow detection, a string ReverseString, a thread-safe Employee/Manager implementation, and a concurrent BFS query processor using a worker-pool.

Changes

Cohort / File(s) Summary
Challenge 1: Integer Arithmetic
challenge-1/submissions/shahzodshafizod/solution-template.go
Adds Sum(a int, b int) (int, error) with overflow checks against math.MaxInt/math.MinInt, a sentinel errOverflow, and a CLI reading two comma-separated ints.
Challenge 2: String Reversal
challenge-2/submissions/shahzodshafizod/solution-template.go
Adds exported ReverseString(s string) string (rune-based reversal using slices.Reverse) and a simple CLI that reads a line and prints the reversed string.
Challenge 3: Employee/Manager (concurrency-safe)
challenge-3/submissions/shahzodshafizod/solution-template.go
Adds exported Employee and Manager types; Manager holds Employees, totalSalary, and mu sync.RWMutex, plus methods AddEmployee, RemoveEmployee, GetAverageSalary, FindEmployeeByID with proper locking and incremental salary tracking.
Challenge 4: Concurrent BFS
challenge-4/submissions/shahzodshafizod/solution-template.go
Adds ConcurrentBFSQueries(graph map[int][]int, queries []int, numWorkers int) map[int][]int implementing a worker-pool with jobChan/resultChan and internal bfs(graph, start) []int helper; returns per-query BFS visitation orders.

Sequence Diagram

sequenceDiagram
    participant Main as Main / Caller
    participant JobChan as Job Channel (queue)
    participant Worker as Worker Goroutine
    participant BFS as bfs Helper
    participant ResultChan as Result Channel

    Main->>JobChan: enqueue start nodes (queries)
    Main->>Worker: spawn N workers
    Worker->>JobChan: receive start node
    Worker->>BFS: call bfs(graph, start)
    BFS->>BFS: traverse graph (BFS)
    BFS-->>Worker: return visitation order
    Worker->>ResultChan: send {start, order}
    ResultChan-->>Main: deliver results
    Main->>Main: aggregate into map[int][]int and return
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 I hop through lines of code tonight,
Sums that guard from overflow's bite,
Strings reversed with a whiskered spin,
Managers counting salaries within,
Workers BFS until the moon is bright 🥕

🚥 Pre-merge checks | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ⚠️ Warning The pull request title claims to add solutions for Challenges 1-7, but the raw summary only shows implementation details for Challenges 1-4. The title is misleading about the scope of changes. Update the title to accurately reflect the scope: 'Add solutions for Challenges 1-4 by shahzodshafizod' to match the actual changes included in this pull request.
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to assess whether the description relates to the changeset. Add a description explaining the solutions implemented for challenges 1-4 and their purpose or approach.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

🧹 Nitpick comments (10)
challenge-2/submissions/shahzodshafizod/solution-template_test.go (2)

25-44: Consider testing ReverseString directly for faster and more reliable tests.

The current approach spawns a subprocess for each test case, which adds overhead and external dependencies (requires go in PATH). Since ReverseString is exported and in the same package, you can test it directly:

♻️ Suggested alternative using direct function call
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			cmd := exec.Command("go", "run", "solution-template.go")
-			stdin := strings.NewReader(tt.input)
-			var stdout, stderr bytes.Buffer
-			cmd.Stdin = stdin
-			cmd.Stdout = &stdout
-			cmd.Stderr = &stderr
-
-			err := cmd.Run()
-			if err != nil {
-				t.Fatalf("Error running the program: %v\nStderr: %s", err, stderr.String())
-			}
-
-			output := strings.TrimSpace(stdout.String())
+			output := ReverseString(tt.input)
 			if output != tt.expected {
 				t.Errorf("For input '%s', expected output '%s', got '%s'", tt.input, tt.expected, output)
 			}
 		})
 	}

This would also allow removing the bytes, os/exec, and strings imports.


16-23: Good test coverage; consider adding a Unicode/emoji test case.

The test cases cover important scenarios well. Since the implementation uses []rune to handle Unicode correctly, consider adding a test case with multi-byte characters to validate this behavior:

 		{"Special characters", "12345!@#$%", "%$#@!54321"},
 		{"Mixed case", "GoLang", "gnaLoG"},
+		{"Unicode emoji", "Hello🌍🚀", "🚀🌍olleH"},
 	}
challenge-1/submissions/shahzodshafizod/solution-template_test.go (1)

24-25: Duplicate test names cause unclear test output.

Both overflow test cases are named "Overflow case", resulting in Go appending #01 to distinguish them in test output. Use distinct names for clarity.

♻️ Proposed fix for distinct test names
-		{"Overflow case", fmt.Sprintf("%d, %d", math.MaxInt, math.MaxInt), "errOverflow"},
-		{"Overflow case", fmt.Sprintf("%d, %d", math.MinInt, math.MinInt), "errOverflow"},
+		{"Positive overflow", fmt.Sprintf("%d, %d", math.MaxInt, math.MaxInt), "errOverflow"},
+		{"Negative overflow", fmt.Sprintf("%d, %d", math.MinInt, math.MinInt), "errOverflow"},
challenge-3/submissions/shahzodshafizod/solution-template.go (1)

26-28: Remove commented-out code.

Dead code should be removed to keep the codebase clean. If the sorting logic is needed for reference, it can be recovered from version control.

challenge-3/submissions/shahzodshafizod/solution-template_test.go (2)

8-23: Consider adding sorted-order verification.

The test verifies employee count but doesn't verify that employees remain sorted by ID. Given that FindEmployeeByID and RemoveEmployee rely on binary search, consider asserting the sorted invariant after adds.


1-5: Consider adding concurrency tests.

The Manager implementation uses sync.RWMutex for thread safety, but there are no tests exercising concurrent Add/Remove/Find operations. Parallel tests using t.Parallel() and goroutines would help validate the thread-safety guarantees.

challenge-4/submissions/shahzodshafizod/solution-template.go (2)

16-17: Remove stale placeholder comments.

Lines 16-17 still say the function is unimplemented; they now contradict the code and should be removed.


59-79: Trim non-essential scaffolding from the submission file.

The commented-out alternative implementation and demo main() add noise to the challenge solution and make review/maintenance harder.

Also applies to: 101-117

challenge-4/submissions/shahzodshafizod/solution-template_test.go (2)

213-216: Turn warning-only timing checks into enforceable assertions.

Both branches only t.Logf(...), so sequential implementations can still pass these tests. If these checks are intended as requirements, switch to t.Errorf/t.Fatalf with a stable tolerance policy.

Also applies to: 266-269


120-123: Use unique-query cardinality for map-size assertions.

ConcurrentBFSQueries returns map[int][]int, so duplicate queries collapse to one key. Comparing len(results) to len(tc.queries) is fragile for future duplicate-query cases.


ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a7ac764 and 8d56ab9.

📒 Files selected for processing (8)
  • challenge-1/submissions/shahzodshafizod/solution-template.go
  • challenge-1/submissions/shahzodshafizod/solution-template_test.go
  • challenge-2/submissions/shahzodshafizod/solution-template.go
  • challenge-2/submissions/shahzodshafizod/solution-template_test.go
  • challenge-3/submissions/shahzodshafizod/solution-template.go
  • challenge-3/submissions/shahzodshafizod/solution-template_test.go
  • challenge-4/submissions/shahzodshafizod/solution-template.go
  • challenge-4/submissions/shahzodshafizod/solution-template_test.go

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.

♻️ Duplicate comments (1)
challenge-3/submissions/shahzodshafizod/solution-template.go (1)

54-60: ⚠️ Potential issue | 🟠 Major

Avoid returning a pointer to internal slice storage.

Line 59 returns &m.Employees[index]; after unlock, concurrent append/remove can invalidate that pointer and expose unsafe shared mutation.

🐛 Proposed fix (keeps signature intact)
 func (m *Manager) FindEmployeeByID(id int) *Employee { // O(n)
 	m.mu.RLock()
 	defer m.mu.RUnlock()
 	for index := range m.Employees {
 		if m.Employees[index].ID == id {
-			return &m.Employees[index]
+			e := m.Employees[index]
+			return &e
 		}
 	}
 	return nil
 }
🧹 Nitpick comments (1)
challenge-4/submissions/shahzodshafizod/solution-template.go (1)

57-77: Remove the large commented-out implementation block.

Keeping two implementations (one commented) in the submission file makes maintenance harder and increases drift risk.


ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4f9c73e and 4bd715e.

📒 Files selected for processing (2)
  • challenge-3/submissions/shahzodshafizod/solution-template.go
  • challenge-4/submissions/shahzodshafizod/solution-template.go

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


ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4bd715e and 53799f4.

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

@shahzodshafizod
Copy link
Contributor Author

How can I merge this MR into main?

@shahzodshafizod shahzodshafizod changed the title shahzodshafizod: challenges 1-4 shahzodshafizod: challenges 1-6 Mar 3, 2026
@shahzodshafizod shahzodshafizod changed the title shahzodshafizod: challenges 1-6 shahzodshafizod: challenges 1-7 Mar 3, 2026
@shahzodshafizod shahzodshafizod changed the title shahzodshafizod: challenges 1-7 Add solutions for Challenges 1-7 by shahzodshafizod Mar 3, 2026
@RezaSi RezaSi merged commit ee9acbe into RezaSi:main Mar 16, 2026
11 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