Gyanthakur / GFG_POTD

Add GfG potd fcfs
26 stars 52 forks source link

Two-pass approach used to solve the problem #204

Closed Avnee29 closed 3 weeks ago

Avnee29 commented 4 weeks ago

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.