Multiply Without the Multiplication Operator
Updated
Problem statement
Given two integers a and b, return their product a * b without using the multiplication operator. Addition, subtraction, comparisons and bit operations such as shifts are allowed.
The product can be as large as 10^18 in size, so return it as a 64-bit integer.
Note: the judge checks only the returned value. Not using * is the point of the exercise, but it is not checked automatically.
Function
multiply(a: int, b: int) → longExamples
Example 1
a = 6b = 7return = 426 times 7 is 42.
Example 2
a = -4b = 9return = -36Exactly one number is negative, so the product is negative: -36.
Example 3
a = -3b = -5return = 15Both numbers are negative, so the product is positive: 15.
Constraints
-10^9 <= a, b <= 10^9
More Microsoft Onsite Interview questions
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
- Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
- Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
- Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
- Coin ChangeONSITE INTERVIEW · Seen Oct 2026
- Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
- Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
- Totals from a Tiered Rate TableONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Raise a Number to an Integer PowerAdobe · PHONE SCREENAdobe interview questions
- Find the Missing Number from 1 to nHyperVerge · ONSITE INTERVIEW
- Swap Two Integers Without a Temporary VariableOracle · ONSITE INTERVIEWOracle interview questions
- Add Two Binary StringsPeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
- Check Whether a Byte Is NonzeroZscaler · ONSITE INTERVIEWZscaler interview questions
- Fibonacci with Input ValidationMorgan Stanley · ONSITE INTERVIEWMorgan Stanley interview questions
- Find the Lowest Set Bit PositionExpedia · OA · ONSITE INTERVIEWExpedia interview questions
- FactorialAMD · ONSITE INTERVIEWAMD interview questions
- Path Between Two Nodes of a Fibonacci TreeDatabricks · ONSITE INTERVIEWDatabricks interview questions
- Bayesian Scenario ClassifierAmazon · ONSITE INTERVIEW