Karatsuba Algorithm | Practice | GeeksforGeeks

Given two binary strings A and B that represent value of two integers, find the product of two strings in Decimal Value.
 
Example 1:
Input:
A = "1100" , B = "01"
Output:
12
Explanation:
Decimal representation of A is 12 and
that of B is 1. So, A*B gives the
output 12.
Example 2:
Input:
A = "01" , B = "01"
Output:
1
Explanation:
Decimal representation of both A and 
B is 1. So, A*B gives the output 1.
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function karatsubaAlgo() which takes Strings A and B as input and returns the answer.
 
Expected Time Complexity: O(Length of Binary String)
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= |A|,|B| <= 25
0
xcode991 week ago
function type is given integer and output of 10e11 ??? how is it possible??
 
 
Input:  
01011001111101001110101 01000110010011011
And Your Code's output is: 
-1271684905
Its Correct output is: 
106102497495
Output Difference 
-1271684905
+1
sdmrf1 month ago
Python Soln:
    def karatsubaAlgo(self, A , B):       return int(A,2)*int(B,2)
0
kishan20012 months ago
 static Long karatsubaAlgo(String A, String B) {       int f=Integer.parseInt(A,2);       int s=Integer.parseInt(B,2);              return (long)f*s;   }
-1
chessnoobdj3 months ago
C++ one liner
unsigned long long karatsubaAlgo(string A, string B) {
        return (bitset<64>(A).to_ullong())*(bitset<64>(B).to_ullong());
    }
+1
rdm1234 months ago
def karatsubaAlgo(self, A , B):
        
        a=int(A,2)
        b=int(B,2)
        return a*b
0
Karan Bhat1 year ago
Karan Bhat
Execution Time : 0.02 sec in Python3
class Solution:def karatsubaAlgo(self, A , B):# code here num1, num2, x, y = 0, 0, 1, 1A = A[::-1]B = B[::-1]for i in range(0, len(A))num1 += (int(A[i]))*x *= 2for j in range(0, len(B)) :num2 += (int(B[j]))*yy *= 2return num1*num2
0
Debarshi Maitra1 year ago
Debarshi Maitra
Execution Time:0.01 : https://ide.geeksforgeeks.o...
0
Santosh2 years ago
Santosh
Implemented Karatsuba Algorithm to sove the problem in JAVA..https://practice.geeksforge...
0
Codys2 years ago
Codys
This is so simple program. But how to implement karatsuba algorithm ?
0
Shivam2 years ago
Shivam
#include <bits stdc++.h="">using namespace std;int main(){int t;cin>>t;while(t--){string s,m;cin>>s>>m;int d = stoi(s,0,2);int e = stoi(m,0,2);cout<<d*e<<"\n"; }="" }="" <="" code="">
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.