Skip to content

add two sum problem #4364

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 9 commits into from
Sep 12, 2023
Merged

add two sum problem #4364

merged 9 commits into from
Sep 12, 2023

Conversation

BamaCharanChhandogi
Copy link
Member

@BamaCharanChhandogi BamaCharanChhandogi commented Sep 10, 2023

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.

@BamaCharanChhandogi
Copy link
Member Author

@siriak please check.

Copy link
Member

@vil02 vil02 left a comment

Choose a reason for hiding this comment

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

I would highly recommend to add the missing test. Besides that, some small suggestions from my side.

Copy link
Member

@vil02 vil02 left a comment

Choose a reason for hiding this comment

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

Sorry for a mammoth suggestion. Short summary:

  • I suggest to use Optional<Pair<Integer, Integer>> as a return type. Why? If the solution exists, the output should be two numbers. I suggest it to encode this information into the return type (int[] might be arbitrarily long),
  • I renamed map to valueToIndex. Maybe it is still not perfect, but stores some information what is the key and what is the value of this map,
  • renamed nums to values,
  • adapted tests,
  • added a new test, so that there is 100 % coverage.

@BamaCharanChhandogi
Copy link
Member Author

@siriak check!

@vil02 vil02 enabled auto-merge (squash) September 12, 2023 05:27
Copy link
Member

@siriak siriak left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@vil02 vil02 merged commit 34cf6da into TheAlgorithms:master Sep 12, 2023
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.

4 participants