Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Multiply Without Operator

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Multiply Without Operator. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Kroger’s pricing systems may need arithmetic utilities that operate under restricted-operation rules. Implement integer multiplication without using Python’s multiplication operator, built-in multiplication functions, exponentiation, or string conversion.

Formal Specification

Write multiply_integers(a, b) that accepts two integers and returns their mathematical product as an integer. The inputs may be positive, negative, or zero. Your implementation may use addition, subtraction, division or remainder, comparisons, loops, and bit operations, but it must not use * anywhere in the algorithm.

Aim for an algorithm that uses repeated doubling rather than adding one operand once for every unit of the other operand. The result will fit within the supported integer range.

Constraints

  • -10^9 <= a, b <= 10^9
  • The mathematical product fits within the supported integer range.
  • The multiplication operator and multiplication-related built-ins are prohibited.
  • Inputs are ordinary Python integers.

Function Signature

def multiply_integers(a, b):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output