Given an array arr of distinct integers, rearrange the array such that the first element is the largest, the second element is the smallest, the third element is the second largest, and so on.
Fixes: #228
Use [x] to represent a checked (ticked) box.✅
Use [ ] to represent an unchecked box.❌
Type of Change
[x] Question Added
[x] Solution Added
[x] Other (please specify):
Checklist
[x] I have performed a self-review of my code.
[x] I have commented my code, particularly in hard-to-understand areas.
[x] I have made corresponding changes to the documentation (if applicable).
[x] My changes generate no new warnings.
[x] I have added tests to cover my changes (if applicable).
[x] All new and existing tests pass.
Additional Notes
Complexity: A straightforward approach to this problem involves sorting the array and then rearranging the elements, resulting in a time complexity of O(nlogn).Edge Cases: Ensure the solution handles arrays with fewer than two elements appropriately.
Description
Given an array arr of distinct integers, rearrange the array such that the first element is the largest, the second element is the smallest, the third element is the second largest, and so on.
Fixes: #228
Use [x] to represent a checked (ticked) box.✅ Use [ ] to represent an unchecked box.❌
Type of Change
Checklist
Additional Notes
Complexity: A straightforward approach to this problem involves sorting the array and then rearranging the elements, resulting in a time complexity of O(nlogn).Edge Cases: Ensure the solution handles arrays with fewer than two elements appropriately.