DSA interview question
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).
int minimumMultiplications(const vector<int>& arr, int start, int end); // values mod 100000
Input (arr, start, end) | Output | Explanation |
|---|---|---|
([2, 5, 7], 3, 30) | 2 | 3 → 6 → 30 |
([3, 4, 65], 7, 66175) | 4 | 7 → 21 → 63 → 4095 → 266175 mod 100000 |
([2, 3], 1, 12) | 3 | No 2-press product equals 12 |
([10], 5, 7) | -1 | Multiples of 10 never end in 7 |
([2], 1, 1) | 0 | Already there |
(Confirm: all arithmetic is modulo 100000; 0 ≤ start, end < 100000; buttons can be pressed any number of times.)
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 interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in