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

POTD_28_OCT_2024_REMOVE_DUPLICATES_IN_AN_ARRAY #220

Closed
Varalakshmi2354 opened this issue Oct 28, 2024 · 1 comment · Fixed by #221
Closed

POTD_28_OCT_2024_REMOVE_DUPLICATES_IN_AN_ARRAY #220

Varalakshmi2354 opened this issue Oct 28, 2024 · 1 comment · Fixed by #221

Comments

@Varalakshmi2354
Copy link
Contributor

Varalakshmi2354 commented Oct 28, 2024

📝 Description

Given an array of positive integers, the task is to remove all duplicate numbers while preserving the order of their first occurrence. The function should return a new array containing only the unique elements.

💡 Enhancement / Feature Request (if applicable)

Why It's Useful
Removing duplicates from an array is essential in various scenarios, including:

1.Data Processing: Cleaning datasets for analysis by eliminating redundancy.
2.Memory Optimization: Reducing the size of data structures when only unique elements are needed.
3.User Interfaces: Ensuring that lists displayed to users (e.g., dropdowns or selections) do not contain repeated entries.

How It Should Work
1.Iterate Through the Array: For each element in the input array, check if it has been encountered before.
2.Track Unique Elements: Use a set to keep track of elements that have already been added to the result.
3.Build the Result Array: Append elements to the result array only if they are unique.
4.Return the Result: The final output should be an array containing all unique elements in their first-encountered order.

🌐 Additional Context

Complexity: The proposed solution has a time complexity of 𝑂(𝑛), where n is the size of the array, since each element is processed once. The space complexity is also 𝑂(𝑛) for storing the unique elements and the set.

Edge Cases: Handle cases where the input array is empty or has only one element by returning an empty array or the array itself, respectively.

Copy link

Welcome, @Varalakshmi2354! Thanks for raising the issue.
Soon the maintainers/owner will review it and provide you with feedback/suggestions.
Make sure to star this awesome repository and follow the account!

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

Successfully merging a pull request may close this issue.

1 participant