Skip to content

Instantly share code, notes, and snippets.

View Robogeek95's full-sized avatar
๐ŸŒ
Somewhere on earth

Azeez Lukman Robogeek95

๐ŸŒ
Somewhere on earth
View GitHub Profile
@Robogeek95
Robogeek95 / countUniqueValues.js
Created December 4, 2023 18:43
Multiple Pointers - countUniqueValues
function countUniqueValues(arr) {
if (arr.length === 0) {
return 0;
}
let i = 0; // Slow pointer
for (let j = 1; j < arr.length; j++) {
if (arr[i] !== arr[j]) {
i++;
arr[i] = arr[j];