input [1,8,9]
output [[1],[1,8],[1,8,9],[8],[8,9],[9]]
It appears to be a subset array, but I am aiming to achieve this output using a two-pointer approach. Let's assign leftP=0, rightP=0; and then utilizing a for loop, the rightP will iterate until the end of the array and then the leftP will move by 1...
1 -> [1], [1,8],[1,8,9]
8 -> [8],[8,9]
9 -> [9]
function solution(arr) {
let totalArr = [];
let leftP = 0;
for(let rightP=0; rightP<arr.length; rightP++) {
totalArr.push(arr[rightP]);
// this is where I am encountering an obstacle
while()
}
}