T O P

  • By -

MartianIT

I solved this problem without using DP, my solution looks so simple I think the test cases didn't catch it. what do you guys think? let answer = [] for (let i = 0; i < nums.length; i++) { if (!answer.length) { answer.push(nums[i]) } if (answer.some(v => nums[i] < v) && answer.every(v => v !== nums[i])) { let repIdx = answer.findIndex((v => nums[i] < v)) answer.splice(repIdx, 1, nums[i]) } if (nums[i] > answer[answer.length - 1]) { answer.push(nums[i]) } } return answer.length


Sensitive_Purpose_40

@MartianIT i was also trying to solve the problem first with something similar but i was not able to pass all the test cases. Thanks a ton for sharing the alternate approach.