Note:
Assume ‘0’ as the invalid number and all others as a valid number. The sequence of the valid numbers is present in the same order.
Example:
Input: arr[] = [2, 2, 0, 4, 0, 8]
Output: [4, 4, 8, 0, 0, 0]
Explanation: At index 0 and 1 both the elements are the same. So, we will change the element at index 0 to 4 and the element at index 1 is 0 then we will shift all the zeros to the end of the array. So, the array will become [4, 4, 8, 0, 0, 0].Input: arr[] = [0, 2, 2, 2, 0, 6, 6, 0, 0, 8] Output: [4, 2, 12, 8, 0, 0, 0, 0, 0, 0]
Explanation: At index 5 and 6 both the elements are the same. So, we will change the element at index 5 to 12 and the element at index 6 is 0. We will change the element at index 1 to 4 and the element at index 2 is 0. Then we shift all the zeros to the end of the array. So, array will become [4, 2, 12, 8, 0, 0, 0, 0, 0, 0]. Expected Time Complexity: O(n)
Expected Auxiliary Space: O(n)
Constraints:
1 ≤ arr.size() ≤ 105
1 ≤ arr[i] ≤ 106
Description
Please include a summary of the changes and the related issue(s) this pull request addresses. Include any relevant context or background information.
Fixes: #[issue_number] (replace with the issue number, if applicable)
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
Please add any other information that is relevant to this pull request, including potential risks, alternative solutions considered, or future improvements.
Note: Assume ‘0’ as the invalid number and all others as a valid number. The sequence of the valid numbers is present in the same order.
Example: Input: arr[] = [2, 2, 0, 4, 0, 8] Output: [4, 4, 8, 0, 0, 0] Explanation: At index 0 and 1 both the elements are the same. So, we will change the element at index 0 to 4 and the element at index 1 is 0 then we will shift all the zeros to the end of the array. So, the array will become [4, 4, 8, 0, 0, 0].Input: arr[] = [0, 2, 2, 2, 0, 6, 6, 0, 0, 8] Output: [4, 2, 12, 8, 0, 0, 0, 0, 0, 0] Explanation: At index 5 and 6 both the elements are the same. So, we will change the element at index 5 to 12 and the element at index 6 is 0. We will change the element at index 1 to 4 and the element at index 2 is 0. Then we shift all the zeros to the end of the array. So, array will become [4, 2, 12, 8, 0, 0, 0, 0, 0, 0]. Expected Time Complexity: O(n) Expected Auxiliary Space: O(n) Constraints: 1 ≤ arr.size() ≤ 105 1 ≤ arr[i] ≤ 106
Description
Please include a summary of the changes and the related issue(s) this pull request addresses. Include any relevant context or background information.
Fixes: #[issue_number] (replace with the issue number, if applicable)
Use [x] to represent a checked (ticked) box.✅ Use [ ] to represent an unchecked box.❌
Type of Change
Checklist
Additional Notes
Please add any other information that is relevant to this pull request, including potential risks, alternative solutions considered, or future improvements.