Skip to content

Conversation

@azs0309
Copy link
Contributor

@azs0309 azs0309 commented Dec 19, 2025

Challenge 19 Solution

Submitted by: @azs0309
Challenge: Challenge 19

Description

This PR contains my solution for Challenge 19.

Changes

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

Walkthrough

Adds a new Go file containing four exported slice utility functions (FindMax, RemoveDuplicates, ReverseSlice, FilterEven) and a main function demonstrating their usage with sample data. Functions handle empty inputs gracefully.

Changes

Cohort / File(s) Summary
Challenge 19 solution
challenge-19/submissions/azs0309/solution-template.go
New file introducing four exported utility functions for slice operations: FindMax (returns maximum or 0), RemoveDuplicates (preserves order), ReverseSlice (returns reversed slice), and FilterEven (filters even numbers). Includes main function demonstrating all utilities.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify correctness of slice logic in each utility function
  • Confirm edge case handling for empty inputs
  • Check that order preservation in RemoveDuplicates is implemented correctly

Possibly related PRs

Pre-merge checks

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add solution for Challenge 19 by azs0309' clearly describes the main change: adding a solution file for Challenge 19.
Description check ✅ Passed The description is directly related to the changeset, explaining that it contains a solution for Challenge 19 with appropriate details about the file added.
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: 1

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

44-65: Consider using a map for better performance.

The current implementation uses nested loops resulting in O(n²) time complexity. For larger slices, this could impact performance. A map-based approach would reduce this to O(n).

🔎 Proposed refactor using a map
 func RemoveDuplicates(numbers []int) []int {
 	if len(numbers) == 0{
 	 return []int{}
 	}
-	result := make([]int,0,len(numbers))
-
-	result = append(result, numbers[0])
+	seen := make(map[int]bool)
+	result := make([]int, 0, len(numbers))
+
 	for _, number := range numbers {
-	    found := false
-	    for _, inresult := range result {
-	        if number == inresult {
-	            found = true
-	            }
-	        }
-	   if !found {
+	    if !seen[number] {
+	        seen[number] = true
 	       result = append(result, number)
 	   }
 	}
 	return result
 }
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 669bf54 and 883aee8.

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

7-26: LGTM! Clear demonstration code.

The main function effectively demonstrates all utility functions with appropriate test data and output.


28-42: LGTM! Efficient maximum-finding implementation.

The function correctly finds the maximum value with O(n) time complexity and handles empty slices as documented.


75-79: LGTM! Correct reverse implementation.

The reverse logic correctly iterates backwards and builds the reversed slice efficiently.


82-95: LGTM! Correct even number filtering.

The function correctly filters even numbers using the modulo operator and handles empty input appropriately.

Comment on lines +72 to +74
// if len(slice) == 1{
// return slice
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Remove commented-out code.

The commented lines are unnecessary dead code and should be removed to keep the codebase clean.

🔎 Proposed fix
     if len(slice) == 0{
 	 return []int{}
 	}
-// 	if len(slice) == 1{
-// 	 return slice
-// 	}
 	reversed := make([]int,0,len(slice))
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// if len(slice) == 1{
// return slice
// }
if len(slice) == 0{
return []int{}
}
reversed := make([]int,0,len(slice))
🤖 Prompt for AI Agents
In challenge-19/submissions/azs0309/solution-template.go around lines 72 to 74,
there are three commented-out lines (an if len(slice) == 1 check and return)
that are dead code; remove these commented lines entirely to clean up the file
and keep the codebase tidy, leaving no leftover commented logic.

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