Skip to content
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

Solved 2 sum problem in CPP #7310 #7382

Conversation

sourabhsinghrajput45
Copy link

Added 2Sum problem solution using C++ with unordered_map for O(n) time complexity

Problem

2 sum problem in CPP #7310

Solution

Implemented the 2Sum algorithm using an unordered_map to achieve O(n) time complexity by storing complements and checking for matches during iteration.

Changes Proposed

  • Added twoSum function to solve the 2Sum problem.
  • Utilized unordered_map to track the complements of numbers in the input array.
  • Return the indices of the two numbers that sum to the target.

Other Changes

  • Refactored the main function to test the solution.

Added 2Sum problem solution using C++ with unordered_map for O(n) time complexity
@sourabhsinghrajput45 sourabhsinghrajput45 closed this by deleting the head repository Oct 1, 2024
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