Hi @jessie_Zhao
My name is Shahrukh Naeem. I hope everything is going well with you. Thank you for reaching out about this. I will try my best to answer your query!
Lets take an example
Input list : [1, 2, 3, 4]
Result is an array which is empty initially.
Left variable stores 1 intially.
i is loop control variable which iterates the list elements.
When i = 0
currentproduct sets to 1.
First iteration of ele = list[0]= 1 β> currentproduct = 11 =1
Second iteration of ele = list[1]= 2 β> currentproduct = 12=2
Third iteration of ele = list[2]= 3 β> currentproduct = 23=6
Fourth iteration of ele = list[3]= 4 β> currentproduct = 64=24
currentproduct * left = 241=24 is appended in Result array at first index
left is 1
Updated left is 2
When i = 1
currentproduct resets to 1.
First iteration of ele = list[1]= 2 β> currentproduct = 12=2
Second iteration of ele = list[2]= 3 β> currentproduct = 23=6
Third iteration of ele = list[3]= 4 β> currentproduct = 64=24
currentproduct * left = 241=24 is appended in Result array at second index
left is 2
Updated left is 6
When i = 2
currentproduct resets to 1.
First iteration of ele = list[2]= 3 β> currentproduct = 13=3
Second iteration of ele = list[3]= 4 β> currentproduct = 34=12
currentproduct * left = 122=24 is appended in Result array at third index
left is 6
Updated left is 24
When i = 3
currentproduct resets to 1.
First iteration of ele = list[3]= 4 β> currentproduct = 14=4
currentproduct * left = 46 =24 is appended in Result array at fourth indexResult Array is [ 24, 24, 24 ,24 ]
I hope that this guide is helpful. Remember that I am always available via message to help you with any difficulty you might encounter.
Regards,
Happy Learning