Multiply two linked lists | gfg potd | 01-10-24 | GFG Problem of the day

preview_player
Показать описание
Geeks for Geeks Problem of the Day(POTD) in C++ | Multiply two linked lists | Fully Explained🧠

Solution Code :
🌐 Connect with Me:

#GFG #POTD #geeksforgeeks #problemoftheday #c++
Gfg potd today
Рекомендации по теме
Комментарии
Автор

suppose we have LL1- 25 -> 334
then num1 = 25*10 + 332
num1 = 582
but it should be 25334

Astro-Coder
Автор

but your time complexity will be O(n+m) 


they require O( max ( n, m ) )

long long multiplyTwoLists(Node *first, Node *second) {
// code here
long long num1=0, num2=0
Node* t1=first;
Node* t2=second;

int data;
while(t1 != nullptr && t2 != nullptr){
data=t1->data;
num1=(num1*10+data)%mod;
t1=t1->next;

data=t2->data;
num2=(num2*10+data)%mod;
t2=t2->next;
}

while(t1 != nullptr){
data=t1->data;
num1=(num1*10+data)%mod;
t1=t1->next;
}

while(t2 != nullptr){
data=t2->data;
num2=(num2*10+data)%mod;
t2=t2->next;
}

long long ans=(num1 * num2) % mod;
return ans;

}

i_sumit