Skip to content

Go: Chapter 2 Hash Maps and Sets #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

ineBallardin
Copy link
Contributor

Go Solutions for Chapter 2 - Hash Maps and Sets

This PR adds Go solutions for Chapter 2 - Hash Maps and Sets.

I followed the structure and naming conventions used in the official Python solutions to maintain consistency across languages. However, for variable and function names, I applied Go idiomatic conventions (e.g., camelCase for variables and functions, snake_case for file names). Despite these adaptations, the names remain equivalent to the original solutions to ensure clarity and consistency.

All implementations have been tested to match the expected outputs. Let me know if any adjustments are needed!

Copy link
Collaborator

@Destiny-02 Destiny-02 left a comment

Choose a reason for hiding this comment

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

Hi @ineBallardin, thank your for making a PR to the solutions repository! Please check the comments for the the change(s) requested.

Thanks again for your contributions! 🙂

@@ -0,0 +1,29 @@
package hashmapsandsets

func LongestChainOfConsecutiveNumbers(nums []int) int {
Copy link
Collaborator

Choose a reason for hiding this comment

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

should the function names use camel case?

Copy link
Collaborator

Choose a reason for hiding this comment

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

PascalCase/UpperCamelCase is used in these solutions instead of lowerCamelCase. Are there conventions around which one is used for regular functions?

@@ -0,0 +1,29 @@
package hashmapsandsets

func LongestChainOfConsecutiveNumbers(nums []int) int {
Copy link
Collaborator

Choose a reason for hiding this comment

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

PascalCase/UpperCamelCase is used in these solutions instead of lowerCamelCase. Are there conventions around which one is used for regular functions?

Copy link
Collaborator

@Destiny-02 Destiny-02 left a comment

Choose a reason for hiding this comment

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

LGTM! Just check the comment left by @aikhelis

Use `return []int{}` instead of `return nil` in order to keep consistency with origial Python solition.
return []int{i, idx}
}
}
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Apologies, I forgot to leave here the same suggestion to return an empty list instead of nil.

Copy link
Contributor

@aikhelis aikhelis Feb 3, 2025

Choose a reason for hiding this comment

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

I'm resolving this comment, as per our chat in Discord: Returning nil is a common and idiomatic way in Go to indicate the absence of a result, as it differentiates between "no result" and "an empty result."

We should keep 'nil' here.

@Destiny-02 Destiny-02 self-requested a review February 3, 2025 11:10
}
hashmap[x] = i
}
return []int{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Apologies. I'm removing this suggestion per our chat in Discord: Returning nil is a common and idiomatic way in Go to indicate the absence of a result, as it differentiates between "no result" and "an empty result."

We should keep 'nil' here.

Return `nil` instead of `return []int{}`
Copy link
Contributor

@aikhelis aikhelis left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you, great job, Karine @ineBallardin !

@Destiny-02 Destiny-02 merged commit 3bbec04 into ByteByteGoHq:main Feb 5, 2025
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.

3 participants