Minimum Extra Chocolates

Problem Overview

  • Find the minimum extra chocolates X+Y so Drake’s total becomes a multiple of Alex’s: k(A+X) = B+Y.
  • Input: two integers A and B (0 < A,B < 1e9); Output: the smallest non-negative integer X+Y.
  • Context: fair chocolate sharing where the younger child wants a multiple of the elder’s share.
  • This coding interview problem appears in Unknown interviews and is a common interview question.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: