Skip to content

Conversation

@Pranitan-witt
Copy link

No description provided.

@kengggg kengggg requested a review from Copilot June 19, 2025 07:44
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 completes the exercise by providing working implementations for each task and documenting the approaches in SOLUTION.md.

  • Implements SQL queries and index definitions for campaign pledges (Task 04).
  • Adds a concurrent file stats aggregator with per-file timeouts (Task 03).
  • Fixes the counter race and adjusts ID generation (Task 02).
  • Implements run-length encoding for UTF-8 strings (Task 01) and adds solution notes.

Reviewed Changes

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

Show a summary per file
File Description
tasks/04-sql-reasoning/go/queries.go Added SQLA/SQLB queries and index definitions
tasks/03-sync-aggregator/go/aggregator.go Implemented Aggregate, worker pool, and timeout helpers
tasks/02-fix-the-bug/go/buggy_counter.go Introduced mutex and changed NextID logic
tasks/01-run-length/go/rle.go Added Encode function body for run-length encoding
SOLUTION.md Added solution notes detailing languages, approaches, time

`,
`
CREATE INDEX idx_pledge_donor_id
ON pledge (campaign_id);
Copy link

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

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

The idx_pledge_donor_id index is created on campaign_id instead of donor_id, so it won’t accelerate donor-based lookups. Change it to ON pledge (donor_id).

Suggested change
ON pledge (campaign_id);
ON pledge (donor_id);

Copilot uses AI. Check for mistakes.

select {
case res := <-resultChan:
return res
Copy link

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

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

The select in processFileWithTimeout never handles a timeout case, so timeoutSec is ignored and this can block indefinitely. Add a case <-time.After(time.Duration(timeoutSec)*time.Second): branch to return a timeout status.

Suggested change
return res
return res
case <-time.After(time.Duration(timeoutSec) * time.Second):
return Result{
Path: path,
Lines: 0,
Words: 0,
Status: "timeout",
}

Copilot uses AI. Check for mistakes.
mu.Lock()
defer mu.Unlock()

id := current + int64(rand.Int())
Copy link

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

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

Using rand.Int() here introduces unpredictable and potentially duplicate IDs. If sequential unique IDs are intended, simply return current (or use atomic.AddInt64) under the lock without adding randomness.

Suggested change
id := current + int64(rand.Int())
id := current

Copilot uses AI. Check for mistakes.
Comment on lines +11 to +27
collector := make(map[string]int)
order := make([]string, 0)
for _, c := range s {
char := string(c)
if val, ok := collector[char]; ok {
collector[char] = val + 1
continue
}
collector[char] = 1
order = append(order, char)
}

ans := ""
for _, w := range order {
ans = fmt.Sprintf("%s%s%d", ans, w, collector[w])
}

Copy link

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

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

This approach counts total occurrences rather than consecutive runs, so it fails when characters repeat non-adjacently. Update the algorithm to track and emit run lengths as you iterate through s.

Suggested change
collector := make(map[string]int)
order := make([]string, 0)
for _, c := range s {
char := string(c)
if val, ok := collector[char]; ok {
collector[char] = val + 1
continue
}
collector[char] = 1
order = append(order, char)
}
ans := ""
for _, w := range order {
ans = fmt.Sprintf("%s%s%d", ans, w, collector[w])
}
if len(s) == 0 {
return ""
}
ans := ""
currentChar := string(s[0])
count := 1
for i := 1; i < len(s); i++ {
char := string(s[i])
if char == currentChar {
count++
} else {
ans = fmt.Sprintf("%s%s%d", ans, currentChar, count)
currentChar = char
count = 1
}
}
// Append the last run
ans = fmt.Sprintf("%s%s%d", ans, currentChar, count)

Copilot uses AI. Check for mistakes.

- Language: Go
- Approach: ~~Output is only want to avoid the duplication so I decided to keep it simple for reduce time for other problem~~ After trying to not use mutex so I already got it that I misunderstand the problem
- Why: Should use realible library to generate the uuid instead if id not necessary to order and need to use mutex to lock the accessibility of worker
Copy link

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

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

[nitpick] Spelling/grammar: “realible” should be “reliable”, and the sentence could be clarified. For example: “Use a reliable UUID library when ordering isn’t required, and protect counter access with a mutex.”

Suggested change
- Why: Should use realible library to generate the uuid instead if id not necessary to order and need to use mutex to lock the accessibility of worker
- Why: Use a reliable UUID library when ordering isn’t required, and protect counter access with a mutex to ensure thread safety.

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.

3 participants