PPractick

DSA interview question

Minimum Multiplications to Reach End

Hard · Data structures · Topics: graph, bfs

The problem

A lock has a 5-digit display showing a number (start). Each press of button i multiplies the current value by arr[i] and keeps the result modulo 100000. What's the fewest presses to make the display show end? Return −1 if it's impossible. There are only 100,000 possible values, so treat each value as a graph node, with an edge for each button. The fewest presses is then a BFS shortest path from start to end.

Example: arr = [2, 5, 7], start 3, end 30 → 2 (3 × 2 = 6, 6 × 5 = 30).

Function signature

int minimumMultiplications(const vector<int>& arr, int start, int end);  // values mod 100000

Test cases

Input (arr, start, end)OutputExplanation
([2, 5, 7], 3, 30)23 → 6 → 30
([3, 4, 65], 7, 66175)47 → 21 → 63 → 4095 → 266175 mod 100000
([2, 3], 1, 12)3No 2-press product equals 12
([10], 5, 7)-1Multiples of 10 never end in 7
([2], 1, 1)0Already there

(Confirm: all arithmetic is modulo 100000; 0 ≤ start, end < 100000; buttons can be pressed any number of times.)

How interviewers phrase it

Clarifying questions to ask

  1. Is the modulus fixed at 100000? (Yes.)
  2. Can the same multiplier be used repeatedly? (Yes.)
  3. What if start already equals end? (0 steps.)

Follow-ups to expect

  1. "Why is this a graph problem?"
  2. "Why BFS rather than Dijkstra?"
  3. "Why does the search terminate?"
  4. "What's the worst-case work?"
  5. "Complexity?"

Practise questions like this with a real engineer

On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.

Book a free mock interview

Related questions

All 474 dsa interview questions

DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in