Skip to content

Conversation

@yz4230
Copy link
Contributor

@yz4230 yz4230 commented Nov 19, 2025

Challenge 19 Solution

Submitted by: @yz4230
Challenge: Challenge 19

Description

This PR contains my solution for Challenge 19.

Changes

  • Added solution file to challenge-19/submissions/yz4230/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 19, 2025

Walkthrough

Adds a new Go solution file to challenge-19 containing four exported utility functions for integer slice operations: FindMax (returns maximum value), RemoveDuplicates (removes duplicates while preserving order), ReverseSlice (reverses elements), and FilterEven (filters even numbers). Includes a main function demonstrating these utilities.

Changes

Cohort / File(s) Summary
Challenge-19 Solution
challenge-19/submissions/yz4230/solution-template.go
New file with four exported utility functions for integer slice operations (FindMax, RemoveDuplicates, ReverseSlice, FilterEven) and a demonstration main function

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Code is straightforward with clear, independent utility functions
  • No complex logic or edge case handling beyond empty slice checks
  • Verify correctness of algorithms: especially RemoveDuplicates order preservation and ReverseSlice implementation

Possibly related PRs

Pre-merge checks

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding a solution for Challenge 19 by a specific user.
Description check ✅ Passed The description is directly related to the changeset, providing context about the Challenge 19 solution submission with details about changes and testing.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.

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

🧹 Nitpick comments (1)
challenge-19/submissions/yz4230/solution-template.go (1)

60-67: Consider preallocating with length for better performance.

The logic is correct, but since the final size is known, you can improve performance by preallocating the slice with the correct length and using direct assignment instead of append.

Apply this diff to improve performance:

-func ReverseSlice(slice []int) []int {
-	ret := make([]int, 0, len(slice))
-	for i := range slice {
-	    ret = append(ret, slice[len(slice)-i-1])
-	}
-	return ret
-}
+func ReverseSlice(slice []int) []int {
+	ret := make([]int, len(slice))
+	for i := range slice {
+	    ret[i] = slice[len(slice)-i-1]
+	}
+	return ret
+}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ca8ea29 and 82ae4b2.

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

8-27: LGTM!

The demonstration code appropriately tests all utility functions with a sample dataset.


29-44: LGTM!

The implementation correctly handles empty slices and uses math.MinInt as the initial value, which is a good practice for finding the maximum in an integer slice.


46-58: LGTM!

The implementation correctly removes duplicates while preserving order, and efficiently uses map[int]struct{}{} for tracking seen values.


69-79: LGTM!

The implementation correctly filters even numbers and efficiently preallocates the slice capacity.

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