The algorithm is wrong at 13:24 for [5,3,0,3,1,-1,2]. It fails the condition where i < j < k. When you update variable named as first in code using if condition with -1(from nums[5] in list which is j) , the variable named second holds value 1 (from nums[4] in list which is i). Therefore fails the condition i
We can just use a stack and maintain increasing sequence in it. You explanation also follows the same logic but is difficult to understand in comparison to stack. Let me know if my proposal is incorrect and miss any test cases