Problem solving criteria:stack (https://www.cplusplus.com/reference/stack/stack/) Think about the first input: LRRLR That means 0 ->(L)-> 1 ->(R)-> 2 ->(R)-> 3 ->(L)-> 4 ->(R)-> 5 so we just need to save first R right number in an array (vector) & other number saves in a stack. 0 ->(L)-> 1 general array (vector) stack( 0 ) top of stack= 0 1 ->(R)-> 2 general array (vector)= 1 stack( 0 ) top of stack= 0 2 ->(R)-> 3 general array (vector)= 1 , 2 stack( 0 ) top of stack= 0 3 ->(L)-> 4 general array (vector)= 1 , 2 stack( 0 , 4 )...
I am Tanvir Ahmmad from Bangladesh. Working as a competitive programmer. It will be very pleasure to help you. Happy coding...
Comments
Post a Comment