Skip to content

Added C# solutions for Chapter 1 (Two Pointers) #71

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
merged 2 commits into from
Feb 21, 2025

Conversation

emseto
Copy link
Contributor

@emseto emseto commented Feb 5, 2025

  • is_palindrome_valid
  • largest_container
  • largest_container_brute_force
  • next_lexicographical_sequence
  • pair_sum_sorted
  • pair_sum_sorted_brute_force
  • shift_zeros_to_the_end
  • shift_zeros_to_the_end_naive
  • triplet_sum
  • triplet_sum_brute_force

This follows the naming conventions as described in C# identifier naming rules and conventions.

I'm open to modifying class names if there's something more appropriate. Added unit tests for Chapter 1: Two Pointers here.

@emseto emseto changed the title Added C# solutions for Chapter 1 (Two Intervals) Added C# solutions for Chapter 1 (Two Pointers) Feb 5, 2025
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 @emseto, thanks for making the first PR to the C# solutions!

I noticed you used public partial class Solution. Are there any downsides to using public class Solution instead? We want to go with the more familiar option.

@emseto
Copy link
Contributor Author

emseto commented Feb 6, 2025

Hi @Destiny-02, thank you for taking a look at the PR! The reason why I used partial classes instead is related to testing and organizing the solutions. Partial classes allow a single class to be split across multiple files, which helps keep methods for individual solutions separate. However, I recognize that this isn't ideal. In an ideal scenario, each file would have a unique class name.

There are a couple of constraints in C# to note:

  1. Class names and methods should follow Pascal case.
  2. Class names and methods cannot be the same unless the method is a constructor.

Because I wasn't sure what to name each class, I settled on public partial class Solution instead of public class Solution to group the solution methods while avoiding naming conflicts.

There are a few ways of remedying this, including:

  1. Assign unique namespaces for each solution (e.g. for IsValidPalindrome, we could have namespace TwoPointers.IsValidPalindrome with public class Solution).
  2. Provide a unique class name for each solution (e.g. for IsValidPalindrome, we could have have IsValidPalindromeSolution class if we wanted to keep the method as IsValidPalindrome).

If each file is going to be self-contained, then I can go ahead and update public partial class Solution to public class Solution. Please let me know your thoughts, and I can make the necessary updates.

@Destiny-02
Copy link
Collaborator

Hi @Destiny-02, thank you for taking a look at the PR! The reason why I used partial classes instead is related to testing and organizing the solutions. Partial classes allow a single class to be split across multiple files, which helps keep methods for individual solutions separate. However, I recognize that this isn't ideal. In an ideal scenario, each file would have a unique class name.

There are a couple of constraints in C# to note:

  1. Class names and methods should follow Pascal case.
  2. Class names and methods cannot be the same unless the method is a constructor.

Because I wasn't sure what to name each class, I settled on public partial class Solution instead of public class Solution to group the solution methods while avoiding naming conflicts.

There are a few ways of remedying this, including:

  1. Assign unique namespaces for each solution (e.g. for IsValidPalindrome, we could have namespace TwoPointers.IsValidPalindrome with public class Solution).
  2. Provide a unique class name for each solution (e.g. for IsValidPalindrome, we could have have IsValidPalindromeSolution class if we wanted to keep the method as IsValidPalindrome).

If each file is going to be self-contained, then I can go ahead and update public partial class Solution to public class Solution. Please let me know your thoughts, and I can make the necessary updates.

Thanks for the explanation @emseto! In this case, we'd like to use public class Solution, even though it will cause an error when the folder is downloaded. Each file will be self-contained and you can think about it like the code will be pasted into an online judge IDE.

@emseto
Copy link
Contributor Author

emseto commented Feb 11, 2025

Hi @Destiny-02 , sounds good and thank you for the clarification! I've updated the PR.

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!

@Destiny-02 Destiny-02 merged commit d03d5c7 into ByteByteGoHq:main Feb 21, 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.

2 participants