Move Zeroes — Two Pointer O(n) In-Place Solution [Meta Interview]
Move all zeroes to end while maintaining relative order of non-zero elements. Optimal O(n) two-pointer solution with minimal writes. Full C, C++, Java, JavaScript and Python code.
webcoderspeed.com
1276 articles
Move all zeroes to end while maintaining relative order of non-zero elements. Optimal O(n) two-pointer solution with minimal writes. Full C, C++, Java, JavaScript and Python code.
Increment a large integer represented as an array by one. Learn the carry propagation pattern with O(n) solutions in C, C++, Java, JavaScript and Python.
Merge two sorted arrays in-place by filling from the end. The classic 3-pointer technique asked at Meta and Microsoft. Full solutions in C, C++, Java, JavaScript and Python.
Remove duplicates from a sorted array in-place using the write pointer pattern. O(n) time, O(1) space. Full solutions in C, C++, Java, JavaScript, Python with follow-up for allowing k duplicates.
Find the element that appears once while every other appears twice. The XOR bit trick gives O(n) time and O(1) space. Full solutions in C, C++, Java, JavaScript, Python plus Single Number II and III extensions.