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_30_OCT_2024_pairs with diff k #227

Merged
merged 1 commit into from
Oct 31, 2024

Conversation

Varalakshmi2354
Copy link
Contributor

Description

Given an array arr[] of positive integers, find and return the maximum sum of the smallest and second smallest element among all possible subarrays of size greater than one. If it is not possible, then return -1.

Fixes: #226

Use [x] to represent a checked (ticked) box.✅
Use [ ] to represent an unchecked box.❌

Type of Change

  • Question Added
  • Solution Added
  • Other (please specify):

Checklist

  • I have performed a self-review of my code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation (if applicable).
  • My changes generate no new warnings.
  • I have added tests to cover my changes (if applicable).
  • All new and existing tests pass.

Additional Notes

Complexity: The brute force approach has a time complexity of O(n3), making it inefficient for large arrays.

Optimized Approach: Consider using a sliding window technique or a priority queue to efficiently find the two smallest elements in each subarray, potentially reducing the time complexity to O(n2).Edge Cases: Handle arrays with fewer than two elements, since valid subarrays of size greater than one won't exist. This would lead to a return value of -1.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Great job, @Varalakshmi2354! Thanks for creating the pull request.
Soon the maintainers/owner will review it and provide you with feedback/suggestions.
Make sure to star this awesome repository and follow the account!

@Gyanthakur Gyanthakur merged commit f1ff360 into Gyanthakur:main Oct 31, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

POTD_30_OCT_2024_PAIRS_WITH_DIFF_K
2 participants