Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

chore(CPlusPlus): Merge two sorted array - Special Manner #1278

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

prateek-narsinghani
Copy link

@prateek-narsinghani prateek-narsinghani commented Oct 25, 2023

PR Checklist:

  • My submission is formatted according to the guidelines in the contributing guide
  • My addition is on refer on the language README.md file
  • My addition does not have a spelling problem
  • My submission has a proper and user-friendly description of the algorithm
  • My submission has the time complexity of the algorithm
  • My submission has sample input-output of the program (NOT FOR PYTHON)

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • New algorithm
  • Optimization in previous algorithms
  • Code style update
  • Refactor
  • Documentation
  • Other, please describe:

Briefly describe the changes in this PR

Merge two sorted array - Special Manner
You're given two sorted arrays. You have to merge them in this manner that if there are some same elements in both of them the third merging array should have less number of same elements

Other information:

Time Complexity: O(len_arr1 + len_arr2) (since we are iterating over all the elements of both arrays)
Space Complexity: O(len_arr1 + len_arr2)

@welcome
Copy link

welcome bot commented Oct 25, 2023

Thanks for opening this pull request! Please check out our contributing guidelines.

@prateek-narsinghani
Copy link
Author

prateek-narsinghani commented Oct 25, 2023

@Arsenic-ATG @UG-SEP @aayushjain7 @Ashborn-SM @Ashad001 @ayo-ajayi @ming-tsai
please have a look at this
since I am new to open source please let me know if I have missed anything.

This is related to Issue: #1272

Copy link

@hamzamehmood67 hamzamehmood67 left a comment

Choose a reason for hiding this comment

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

Great effort!
The code is working fine.
But can we optimize it a little more as there are many conditions that are going to be checked at every iteration?
By the way, you did a great job.

@prateek-narsinghani
Copy link
Author

prateek-narsinghani commented Oct 26, 2023

@hamzamehmood67 Time complexity for my approach is O(m+n) where m, n are size of arrays, the if conditions will not have much impact on the performance of the code

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants