Розмір відео: 1280 X 720853 X 480640 X 360
Показувати елементи керування програвачем
Автоматичне відтворення
Автоповтор
Ive watched soo many videos b4 but cudnt grasp the concept, bro ur explaination was solid and clear... Keep it up
Thank you so much Sameer ❤️Means a lot to me
best explanation of this problem on yt hands down
I didn't find a better video than this one for this problem. This is insanely good
Clear All Your Doubts :class Solution { static ArrayList factorial(int n){ ArrayListfactorial = new ArrayList(); factorial.add(1); int carry = 0; for(int num = 2 ; num = 0;i--){ int product=(factorial.get(i) * num) + carry; carry = product / 10; factorial.set(i,product % 10); } while(carry != 0){ factorial.add(0,carry%10); carry=carry/10; } } return factorial; }}/*Dry run for n = 15:Initial state:n = 15factorial = [1]carry = 0-----------------------------------------------------------------num = 2Inner Loop:i = 0: factorial[0] * 2 + carry = 1 * 2 + 0 = 2, carry = 0, factorial = [2] // 2!=2Carry distribution loop is skipped since carry is 0.num = 3Inner Loop:i = 0: factorial[0] * 3 + carry = 2 * 3 + 0 = 6, carry = 0, factorial = [6] // 3!=6Carry distribution loop is skipped.num = 4Inner Loop:i = 0: factorial[0] * 4 + carry = 6 * 4 + 0 = 24, carry = 2, factorial = [4] Carry distribution loop:Adding carry digits to the beginning: factorial = [2, 4], carry = 0 // 4!=24num = 5Inner Loop:i = 1: factorial[1] * 5 + carry = 4 * 5 + 0 = 20, carry = 2, factorial = [2, 0]i = 0: factorial[0] * 5 + carry = 2 * 5 + 2 = 12, carry = 1, factorial = [2, 0]Carry distribution loop:Adding carry digits to the beginning: factorial = [1, 2, 0], carry = 0 // 5!=120num = 6Inner Loop:i = 2: factorial[2] * 6 + carry = 0 * 6 + 0 = 0, carry = 0, factorial = [1, 1, 0]i = 1: factorial[1] * 6 + carry = 2 * 6 + 0 = 12, carry =1, factorial = [1, 2, 0]i = 0: factorial[0] * 6 + carry = 1 * 6 + 1 = 7, carry = 0, factorial = [7, 2, 0] //6!=720Carry distribution loop is skipped.num = 7Inner Loop:i = 2: factorial[2] * 7 + carry = 0 * 7 + 0 = 0, carry = 0, factorial = [7, 2, 0]i = 1: factorial[1] * 7 + carry = 2 * 7 + 0 = 14, carry = 1, factorial = [7, 4, 0]i = 0: factorial[0] * 7 + carry = 7 * 7 + 1 = 50, carry = 5, factorial = [0, 4, 0]Carry distribution loop:Adding carry digits to the beginning: factorial = [5, 0, 4, 0], carry = 0 //7!=5040num = 8Inner Loop:i = 3: factorial[3] * 8 + carry = 0 * 8 + 0 = 0, carry = 0, factorial = [5, 0, 4, 0]i = 2: factorial[2] * 8 + carry = 4 * 8 + 0 = 32, carry = 3, factorial = [5, 0, 2, 0]i = 1: factorial[1] * 8 + carry = 0 * 8 + 3 = 3, carry = 0, factorial = [5, 3, 2, 0]i = 0: factorial[0] * 8 + carry = 5 * 8 + 0 = 40, carry = 4, factorial = [0, 3, 2, 0]Carry distribution loop:Adding carry digits to the beginning: factorial = [4, 0, 3, 2, 0], carry = 0 //8!=40320num=9Inner Loop:i = 4: factorial[4] * 9 + carry = 0 * 9 + 0 = 0, carry = 0, factorial =[4, 0, 3, 2, 0]i = 3: factorial[3] * 9 + carry = 2 * 9 + 0 = 18, carry = 1, factorial =[4, 0, 3, 8, 0]i = 2: factorial[2] * 9 + carry = 3 * 9 + 1 = 28, carry = 2, factorial =[4, 0, 8, 8, 0]i = 1: factorial[1] * 9 + carry = 0 * 9 + 2 = 2, carry = 0, factorial =[4, 2, 8, 8, 0]i = 0: factorial[0] * 9 + carry = 4 * 9 + 0 = 36, carry = 3, factorial =[6, 2, 8, 8, 0]Carry distribution loop:Adding carry digits to the beginning: factorial =[3, 6, 2, 8, 8, 0], carry = 0 //9!=362880num=10Inner Loop:i = 5: factorial[5] * 10 + carry = 0 * 10 + 0 = 0, carry = 0, factorial=[3, 6, 2, 8, 8, 0]i = 4: factorial[4] * 10 + carry = 8 * 10 + 0 = 80, carry = 8, factorial=[3, 6, 2, 8, 0, 0]i = 3: factorial[3] * 10 + carry = 8 * 10 + 8 = 88, carry = 8, factorial=[3, 6, 2, 8, 0, 0]i = 2: factorial[2] * 10 + carry = 2 * 10 + 8 = 28, carry = 2, factorial=[3, 6, 8, 8, 0, 0]i = 1: factorial[1] * 10 + carry = 6 * 10 + 2 = 62, carry = 6, factorial=[3, 2, 8, 8, 0, 0]i = 0: factorial[0] * 10 + carry = 3 * 10 + 6 = 36, carry = 3, factorial=[6, 2, 8, 8, 0, 0]Carry distribution loop:Adding carry digits to the beginning: factorial =[3, 6, 2, 8, 8, 0, 0], carry = 0 //10!=3628800num=11Inner Loop:i = 6: factorial[6] * 11 + carry = 0 * 11 + 0 = 0, carry = 0, factorial=[3, 6, 2, 8, 8, 0, 0]i = 5: factorial[5] * 11 + carry = 0 * 11 + 0 = 0, carry = 0, factorial=[3, 6, 2, 8, 8, 0, 0]i = 4: factorial[4] * 11 + carry = 8 * 11 + 0 = 88, carry = 8, factorial=[3, 6, 2, 8, 8, 0, 0]i = 3: factorial[3] * 11 + carry = 8 * 11 + 8 = 96, carry = 9, factorial=[3, 6, 2, 6, 8, 0, 0]i = 2: factorial[2] * 11 + carry = 2 * 11 + 9 = 31, carry = 3, factorial=[3, 6, 1, 6, 8, 0, 0]i = 1: factorial[1] * 11 + carry = 6 * 11 + 3 = 69, carry = 6, factorial=[3, 9, 1, 6, 8, 0, 0]i = 0: factorial[0] * 11 + carry = 3 * 11 + 6 = 39, carry = 3, factorial=[9, 9, 1, 6, 8, 0, 0]Carry distribution loop:Adding carry digits to the beginning: factorial =[3, 9, 9, 1, 6, 8, 0, 0], carry = 0 //11!=39916800num=12Inner Loop:i = 7: factorial[7] * 12 + carry = 0 * 12 + 0 = 0, carry = 0, factorial=[3, 9, 9, 1, 6, 8, 0, 0]i = 6: factorial[6] * 12 + carry = 0 * 12 + 0 = 0, carry = 0, factorial=[3, 9, 9, 1, 6, 8, 0, 0]i = 5: factorial[5] * 12 + carry = 8 * 12 + 0 = 0, carry = 9, factorial=[3, 9, 9, 1, 6, 6, 0, 0]i = 4: factorial[4] * 12 + carry = 6 * 12 + 9 = 81, carry = 8, factorial=[3, 9, 9, 8, 1, 6, 0, 0]i = 3: factorial[3] * 12 + carry = 1 * 12 + 8 = 20, carry = 2, factorial=[3, 9, 9, 0, 1, 6, 0, 0]i = 2: factorial[2] * 12 + carry = 9 * 12 + 2 = 110, carry =11, factorial=[3, 9, 0, 0, 1, 6, 0, 0]i = 1: factorial[1] * 12 + carry = 9 * 12 + 11 =119, carry =11, factorial=[3, 9, 0, 0, 1, 6, 0, 0]i = 0: factorial[0] * 12 + carry = 3 * 12 + 11 = 47, carry = 4, factorial=[7, 9, 0, 0, 1, 6, 0, 0]Carry distribution loop:Adding carry digits to the beginning: factorial =[4, 7, 9, 0, 0, 1, 6, 0, 0] //12!=479001600num=13Inner Loop:i = 8: factorial[8] * 13 + carry = 0 * 13 + 0 = 0, carry = 0, factorial=[4, 7, 9, 0, 0, 1, 6, 0, 0]i = 7: factorial[7] * 13 + carry = 0 * 13 + 0 = 0, carry = 0, factorial=[4, 7, 9, 0, 0, 1, 6, 0, 0]i = 6: factorial[6] * 13 + carry = 6 * 13 + 0 = 78, carry = 7, factorial=[4, 7, 9, 0, 0, 1, 8, 0, 0] i = 5: factorial[5] * 13 + carry = 1 * 13 + 7 = 20, carry = 2, factorial=[4, 7, 9, 0, 0, 0, 8, 0, 0] i = 4: factorial[4] * 13 + carry = 0 * 13 + 2 = 2, carry = 0, factorial=[4, 7, 9, 0, 2, 0, 8, 0, 0] i = 3: factorial[3] * 13 + carry = 0 * 13 + 0 = 0, carry =0, factorial=[4, 7, 9, 0, 2, 0, 8, 0, 0]i = 2: factorial[2] * 13 + carry = 9 * 13 + 0 =117, carry =11, factorial=[4, 7, 7, 0, 2, 0, 8, 0, 0]i = 1: factorial[1] * 13 + carry = 7 * 13 + 11 = 102, carry = 10,factorial=[4, 2, 7, 0, 2, 0, 8, 0, 0] i = 0: factorial[0] * 13 + carry = 4 * 13 + 10 = 62, carry = 6, factorial=[2, 2, 7, 0, 2, 0, 8, 0, 0] Carry distribution loop:Adding carry digits to the beginning: factorial=[6, 2, 2, 7, 0, 2, 0, 8, 0, 0] //13!=6227020800num=14Inner Loop:i = 9: factorial[9] * 14 + carry = 0 * 14 + 0 = 0, carry = 0, factorial=[6, 2, 2, 7, 0, 2, 0, 8, 0, 0]i = 8: factorial[8] * 14 + carry = 0 * 14 + 0 = 0, carry = 0, factorial=[6, 2, 2, 7, 0, 2, 0, 8, 0, 0]i = 7: factorial[7] * 14 + carry = 8 * 14 + 0 = 112, carry = 11, factorial=[6, 2, 2, 7, 0, 2, 0, 2, 0, 0]i = 6: factorial[6] * 14 + carry = 0 * 14 + 11 = 11, carry = 1, factorial=[6, 2, 2, 7, 0, 2, 1, 2, 0, 0]i = 5: factorial[5] * 14 + carry = 2 * 14 + 1 = 29, carry = 2, factorial=[6, 2, 2, 7, 0, 9, 1, 2, 0, 0]i = 4: factorial[4] * 14 + carry = 0 * 14 + 2 = 2, carry =0, factorial=[6, 2, 2, 7, 2, 9, 1, 2, 0, 0]i = 3: factorial[3] * 14 + carry = 7 * 14 + 0 = 98, carry =9, factorial=[6, 2, 2, 8, 2, 9, 1, 2, 0, 0]i = 2: factorial[2] * 14 + carry = 2 * 14 + 9 = 37, carry = 3,factorial=[6, 2, 7, 8, 2, 9, 1, 2, 0, 0]i = 1: factorial[1] * 14 + carry = 2 * 14 + 3 = 31, carry = 3, factorial=[6, 1, 7, 8, 2, 9, 1, 2, 0, 0]i = 0: factorial[0] * 14 + carry = 6 * 14 + 3 = 87, carry = 8, factorial=[7, 1, 7, 8, 2, 9, 1, 2, 0, 0]Carry distribution loop:Adding carry digits to the beginning: factorial=[8, 7, 1, 7, 8, 2, 9, 1, 2, 0, 0] //14!=87178291200num=15Inner Loop:i = 10: factorial[10] * 15 + carry = 0 * 15 + 0 = 0, carry = 0, factorial=[8, 7, 1, 7, 8, 2, 9, 1, 2, 0, 0] i = 9: factorial[9] * 15 + carry = 0 * 15 + 0 = 0, carry = 0, factorial=[8, 7, 1, 7, 8, 2, 9, 1, 2, 0, 0] i = 8: factorial[8] * 15 + carry = 2 * 15 + 0 = 30, carry = 3, factorial=[8, 7, 1, 7, 8, 2, 9, 1, 0, 0, 0] i = 7: factorial[7] * 15 + carry = 1 * 15 + 3 = 18, carry = 1, factorial=[8, 7, 1, 7, 8, 2, 9, 8, 0, 0, 0] i = 6: factorial[6] * 15 + carry = 9 * 15 + 1 = 136, carry = 13,factorial=[8, 7, 1, 7, 8, 2, 6, 8, 0, 0, 0]i = 5: factorial[5] * 15 + carry = 2 * 15 + 13 = 43, carry =4, factorial=[8, 7, 1, 7, 8, 3, 6, 8, 0, 0, 0]i = 4: factorial[4] * 15 + carry = 8 * 15 + 4 = 124, carry =12, factorial=[8, 7, 1, 7, 4, 3, 6, 8, 0, 0, 0]i = 3: factorial[3] * 15 + carry = 7 * 15 + 12 = 117, carry = 11,factorial=[8, 7, 1, 7, 4, 3, 6, 8, 0, 0, 0]i = 2: factorial[2] * 15 + carry = 1 * 15 + 11 = 26, carry = 2,factorial=[8, 7, 6, 7, 4, 3, 6, 8, 0, 0, 0]i = 1: factorial[1] * 15 + carry = 7 * 15 + 2 = 107, carry = 10,factorial=[8, 7, 6, 7, 4, 3, 6, 8, 0, 0, 0]i = 0: factorial[0] * 15 + carry = 8 * 15 + 10 = 130, carry = 13,factorial=[0, 7, 6, 7, 4, 3, 6, 8, 0, 0, 0]Carry distribution loop:Adding carry digits to the beginning: Iteration 1:factorial=[3, 0, 7, 6, 7, 4, 3, 6, 8, 0, 0, 0] Iteration 2:factorial=[1, 3, 0, 7, 6, 7, 4, 3, 6, 8, 0, 0, 0] //15!=1307674368000therefore 15!=[1, 3, 0, 7, 6, 7, 4, 3, 6, 8, 0, 0, 0 i.e 1307674368000*/
iski time complexity jada h
One of the finest videos on this problem. No one can teach like you bro
Amazing explanation
Best explanation for this problem on UA-cam
No one can beat his teaching style
bhaiya great explanation..
sab samjh aagaya bhai bas carry wala thoda sa upar se chala gaya
Thanks Bro.really thanks
Thank you for watching 😇❤️
great solution bro.😇
bro please update the DSA sheet man i beg you , they have really good problem not going to lie but the sheet is incomplete .
Sure. Give me a week time. I am travelling this weekend. Will update ♥️🙏
Day 2
Ive watched soo many videos b4 but cudnt grasp the concept, bro ur explaination was solid and clear... Keep it up
Thank you so much Sameer ❤️
Means a lot to me
best explanation of this problem on yt hands down
I didn't find a better video than this one for this problem. This is insanely good
Clear All Your Doubts :
class Solution {
static ArrayList factorial(int n){
ArrayListfactorial = new ArrayList();
factorial.add(1);
int carry = 0;
for(int num = 2 ; num = 0;i--){
int product=(factorial.get(i) * num) + carry;
carry = product / 10;
factorial.set(i,product % 10);
}
while(carry != 0){
factorial.add(0,carry%10);
carry=carry/10;
}
}
return factorial;
}
}
/*
Dry run for n = 15:
Initial state:
n = 15
factorial = [1]
carry = 0
-----------------------------------------------------------------
num = 2
Inner Loop:
i = 0: factorial[0] * 2 + carry = 1 * 2 + 0 = 2, carry = 0, factorial = [2] // 2!=2
Carry distribution loop is skipped since carry is 0.
num = 3
Inner Loop:
i = 0: factorial[0] * 3 + carry = 2 * 3 + 0 = 6, carry = 0, factorial = [6] // 3!=6
Carry distribution loop is skipped.
num = 4
Inner Loop:
i = 0: factorial[0] * 4 + carry = 6 * 4 + 0 = 24, carry = 2, factorial = [4]
Carry distribution loop:
Adding carry digits to the beginning: factorial = [2, 4], carry = 0 // 4!=24
num = 5
Inner Loop:
i = 1: factorial[1] * 5 + carry = 4 * 5 + 0 = 20, carry = 2, factorial = [2, 0]
i = 0: factorial[0] * 5 + carry = 2 * 5 + 2 = 12, carry = 1, factorial = [2, 0]
Carry distribution loop:
Adding carry digits to the beginning: factorial = [1, 2, 0], carry = 0 // 5!=120
num = 6
Inner Loop:
i = 2: factorial[2] * 6 + carry = 0 * 6 + 0 = 0, carry = 0, factorial = [1, 1, 0]
i = 1: factorial[1] * 6 + carry = 2 * 6 + 0 = 12, carry =1, factorial = [1, 2, 0]
i = 0: factorial[0] * 6 + carry = 1 * 6 + 1 = 7, carry = 0, factorial = [7, 2, 0] //6!=720
Carry distribution loop is skipped.
num = 7
Inner Loop:
i = 2: factorial[2] * 7 + carry = 0 * 7 + 0 = 0, carry = 0, factorial = [7, 2, 0]
i = 1: factorial[1] * 7 + carry = 2 * 7 + 0 = 14, carry = 1, factorial = [7, 4, 0]
i = 0: factorial[0] * 7 + carry = 7 * 7 + 1 = 50, carry = 5, factorial = [0, 4, 0]
Carry distribution loop:
Adding carry digits to the beginning: factorial = [5, 0, 4, 0], carry = 0 //7!=5040
num = 8
Inner Loop:
i = 3: factorial[3] * 8 + carry = 0 * 8 + 0 = 0, carry = 0, factorial = [5, 0, 4, 0]
i = 2: factorial[2] * 8 + carry = 4 * 8 + 0 = 32, carry = 3, factorial = [5, 0, 2, 0]
i = 1: factorial[1] * 8 + carry = 0 * 8 + 3 = 3, carry = 0, factorial = [5, 3, 2, 0]
i = 0: factorial[0] * 8 + carry = 5 * 8 + 0 = 40, carry = 4, factorial = [0, 3, 2, 0]
Carry distribution loop:
Adding carry digits to the beginning: factorial = [4, 0, 3, 2, 0], carry = 0 //8!=40320
num=9
Inner Loop:
i = 4: factorial[4] * 9 + carry = 0 * 9 + 0 = 0, carry = 0, factorial =[4, 0, 3, 2, 0]
i = 3: factorial[3] * 9 + carry = 2 * 9 + 0 = 18, carry = 1, factorial =[4, 0, 3, 8, 0]
i = 2: factorial[2] * 9 + carry = 3 * 9 + 1 = 28, carry = 2, factorial =[4, 0, 8, 8, 0]
i = 1: factorial[1] * 9 + carry = 0 * 9 + 2 = 2, carry = 0, factorial =[4, 2, 8, 8, 0]
i = 0: factorial[0] * 9 + carry = 4 * 9 + 0 = 36, carry = 3, factorial =[6, 2, 8, 8, 0]
Carry distribution loop:
Adding carry digits to the beginning: factorial =[3, 6, 2, 8, 8, 0], carry = 0 //9!=362880
num=10
Inner Loop:
i = 5: factorial[5] * 10 + carry = 0 * 10 + 0 = 0, carry = 0, factorial=[3, 6, 2, 8, 8, 0]
i = 4: factorial[4] * 10 + carry = 8 * 10 + 0 = 80, carry = 8, factorial=[3, 6, 2, 8, 0, 0]
i = 3: factorial[3] * 10 + carry = 8 * 10 + 8 = 88, carry = 8, factorial=[3, 6, 2, 8, 0, 0]
i = 2: factorial[2] * 10 + carry = 2 * 10 + 8 = 28, carry = 2, factorial=[3, 6, 8, 8, 0, 0]
i = 1: factorial[1] * 10 + carry = 6 * 10 + 2 = 62, carry = 6, factorial=[3, 2, 8, 8, 0, 0]
i = 0: factorial[0] * 10 + carry = 3 * 10 + 6 = 36, carry = 3, factorial=[6, 2, 8, 8, 0, 0]
Carry distribution loop:
Adding carry digits to the beginning: factorial =[3, 6, 2, 8, 8, 0, 0], carry = 0 //10!=3628800
num=11
Inner Loop:
i = 6: factorial[6] * 11 + carry = 0 * 11 + 0 = 0, carry = 0, factorial=[3, 6, 2, 8, 8, 0, 0]
i = 5: factorial[5] * 11 + carry = 0 * 11 + 0 = 0, carry = 0, factorial=[3, 6, 2, 8, 8, 0, 0]
i = 4: factorial[4] * 11 + carry = 8 * 11 + 0 = 88, carry = 8, factorial=[3, 6, 2, 8, 8, 0, 0]
i = 3: factorial[3] * 11 + carry = 8 * 11 + 8 = 96, carry = 9, factorial=[3, 6, 2, 6, 8, 0, 0]
i = 2: factorial[2] * 11 + carry = 2 * 11 + 9 = 31, carry = 3, factorial=[3, 6, 1, 6, 8, 0, 0]
i = 1: factorial[1] * 11 + carry = 6 * 11 + 3 = 69, carry = 6, factorial=[3, 9, 1, 6, 8, 0, 0]
i = 0: factorial[0] * 11 + carry = 3 * 11 + 6 = 39, carry = 3, factorial=[9, 9, 1, 6, 8, 0, 0]
Carry distribution loop:
Adding carry digits to the beginning: factorial =[3, 9, 9, 1, 6, 8, 0, 0], carry = 0 //11!=39916800
num=12
Inner Loop:
i = 7: factorial[7] * 12 + carry = 0 * 12 + 0 = 0, carry = 0, factorial=[3, 9, 9, 1, 6, 8, 0, 0]
i = 6: factorial[6] * 12 + carry = 0 * 12 + 0 = 0, carry = 0, factorial=[3, 9, 9, 1, 6, 8, 0, 0]
i = 5: factorial[5] * 12 + carry = 8 * 12 + 0 = 0, carry = 9, factorial=[3, 9, 9, 1, 6, 6, 0, 0]
i = 4: factorial[4] * 12 + carry = 6 * 12 + 9 = 81, carry = 8, factorial=[3, 9, 9, 8, 1, 6, 0, 0]
i = 3: factorial[3] * 12 + carry = 1 * 12 + 8 = 20, carry = 2, factorial=[3, 9, 9, 0, 1, 6, 0, 0]
i = 2: factorial[2] * 12 + carry = 9 * 12 + 2 = 110, carry =11, factorial=[3, 9, 0, 0, 1, 6, 0, 0]
i = 1: factorial[1] * 12 + carry = 9 * 12 + 11 =119, carry =11, factorial=[3, 9, 0, 0, 1, 6, 0, 0]
i = 0: factorial[0] * 12 + carry = 3 * 12 + 11 = 47, carry = 4, factorial=[7, 9, 0, 0, 1, 6, 0, 0]
Carry distribution loop:
Adding carry digits to the beginning: factorial =[4, 7, 9, 0, 0, 1, 6, 0, 0] //12!=479001600
num=13
Inner Loop:
i = 8: factorial[8] * 13 + carry = 0 * 13 + 0 = 0, carry = 0, factorial=[4, 7, 9, 0, 0, 1, 6, 0, 0]
i = 7: factorial[7] * 13 + carry = 0 * 13 + 0 = 0, carry = 0, factorial=[4, 7, 9, 0, 0, 1, 6, 0, 0]
i = 6: factorial[6] * 13 + carry = 6 * 13 + 0 = 78, carry = 7, factorial=[4, 7, 9, 0, 0, 1, 8, 0, 0]
i = 5: factorial[5] * 13 + carry = 1 * 13 + 7 = 20, carry = 2, factorial=[4, 7, 9, 0, 0, 0, 8, 0, 0]
i = 4: factorial[4] * 13 + carry = 0 * 13 + 2 = 2, carry = 0, factorial=[4, 7, 9, 0, 2, 0, 8, 0, 0]
i = 3: factorial[3] * 13 + carry = 0 * 13 + 0 = 0, carry =0, factorial=[4, 7, 9, 0, 2, 0, 8, 0, 0]
i = 2: factorial[2] * 13 + carry = 9 * 13 + 0 =117, carry =11, factorial=[4, 7, 7, 0, 2, 0, 8, 0, 0]
i = 1: factorial[1] * 13 + carry = 7 * 13 + 11 = 102, carry = 10,factorial=[4, 2, 7, 0, 2, 0, 8, 0, 0]
i = 0: factorial[0] * 13 + carry = 4 * 13 + 10 = 62, carry = 6, factorial=[2, 2, 7, 0, 2, 0, 8, 0, 0]
Carry distribution loop:
Adding carry digits to the beginning: factorial=[6, 2, 2, 7, 0, 2, 0, 8, 0, 0] //13!=6227020800
num=14
Inner Loop:
i = 9: factorial[9] * 14 + carry = 0 * 14 + 0 = 0, carry = 0, factorial=[6, 2, 2, 7, 0, 2, 0, 8, 0, 0]
i = 8: factorial[8] * 14 + carry = 0 * 14 + 0 = 0, carry = 0, factorial=[6, 2, 2, 7, 0, 2, 0, 8, 0, 0]
i = 7: factorial[7] * 14 + carry = 8 * 14 + 0 = 112, carry = 11, factorial=[6, 2, 2, 7, 0, 2, 0, 2, 0, 0]
i = 6: factorial[6] * 14 + carry = 0 * 14 + 11 = 11, carry = 1, factorial=[6, 2, 2, 7, 0, 2, 1, 2, 0, 0]
i = 5: factorial[5] * 14 + carry = 2 * 14 + 1 = 29, carry = 2, factorial=[6, 2, 2, 7, 0, 9, 1, 2, 0, 0]
i = 4: factorial[4] * 14 + carry = 0 * 14 + 2 = 2, carry =0, factorial=[6, 2, 2, 7, 2, 9, 1, 2, 0, 0]
i = 3: factorial[3] * 14 + carry = 7 * 14 + 0 = 98, carry =9, factorial=[6, 2, 2, 8, 2, 9, 1, 2, 0, 0]
i = 2: factorial[2] * 14 + carry = 2 * 14 + 9 = 37, carry = 3,factorial=[6, 2, 7, 8, 2, 9, 1, 2, 0, 0]
i = 1: factorial[1] * 14 + carry = 2 * 14 + 3 = 31, carry = 3, factorial=[6, 1, 7, 8, 2, 9, 1, 2, 0, 0]
i = 0: factorial[0] * 14 + carry = 6 * 14 + 3 = 87, carry = 8, factorial=[7, 1, 7, 8, 2, 9, 1, 2, 0, 0]
Carry distribution loop:
Adding carry digits to the beginning: factorial=[8, 7, 1, 7, 8, 2, 9, 1, 2, 0, 0] //14!=87178291200
num=15
Inner Loop:
i = 10: factorial[10] * 15 + carry = 0 * 15 + 0 = 0, carry = 0, factorial=[8, 7, 1, 7, 8, 2, 9, 1, 2, 0, 0]
i = 9: factorial[9] * 15 + carry = 0 * 15 + 0 = 0, carry = 0, factorial=[8, 7, 1, 7, 8, 2, 9, 1, 2, 0, 0]
i = 8: factorial[8] * 15 + carry = 2 * 15 + 0 = 30, carry = 3, factorial=[8, 7, 1, 7, 8, 2, 9, 1, 0, 0, 0]
i = 7: factorial[7] * 15 + carry = 1 * 15 + 3 = 18, carry = 1, factorial=[8, 7, 1, 7, 8, 2, 9, 8, 0, 0, 0]
i = 6: factorial[6] * 15 + carry = 9 * 15 + 1 = 136, carry = 13,factorial=[8, 7, 1, 7, 8, 2, 6, 8, 0, 0, 0]
i = 5: factorial[5] * 15 + carry = 2 * 15 + 13 = 43, carry =4, factorial=[8, 7, 1, 7, 8, 3, 6, 8, 0, 0, 0]
i = 4: factorial[4] * 15 + carry = 8 * 15 + 4 = 124, carry =12, factorial=[8, 7, 1, 7, 4, 3, 6, 8, 0, 0, 0]
i = 3: factorial[3] * 15 + carry = 7 * 15 + 12 = 117, carry = 11,factorial=[8, 7, 1, 7, 4, 3, 6, 8, 0, 0, 0]
i = 2: factorial[2] * 15 + carry = 1 * 15 + 11 = 26, carry = 2,factorial=[8, 7, 6, 7, 4, 3, 6, 8, 0, 0, 0]
i = 1: factorial[1] * 15 + carry = 7 * 15 + 2 = 107, carry = 10,factorial=[8, 7, 6, 7, 4, 3, 6, 8, 0, 0, 0]
i = 0: factorial[0] * 15 + carry = 8 * 15 + 10 = 130, carry = 13,factorial=[0, 7, 6, 7, 4, 3, 6, 8, 0, 0, 0]
Carry distribution loop:
Adding carry digits to the beginning:
Iteration 1:
factorial=[3, 0, 7, 6, 7, 4, 3, 6, 8, 0, 0, 0]
Iteration 2:
factorial=[1, 3, 0, 7, 6, 7, 4, 3, 6, 8, 0, 0, 0] //15!=1307674368000
therefore 15!=[1, 3, 0, 7, 6, 7, 4, 3, 6, 8, 0, 0, 0 i.e 1307674368000
*/
iski time complexity jada h
One of the finest videos on this problem. No one can teach like you bro
Amazing explanation
Best explanation for this problem on UA-cam
No one can beat his teaching style
bhaiya great explanation..
sab samjh aagaya bhai bas carry wala thoda sa upar se chala gaya
Thanks Bro.really thanks
Thank you for watching 😇❤️
great solution bro.😇
bro please update the DSA sheet man i beg you , they have really good problem not going to lie but the sheet is incomplete .
Sure. Give me a week time. I am travelling this weekend. Will update ♥️🙏
Day 2