Leetcode Problem 1999. Smallest Greater Multiple Made of Two Digits

1999. Smallest Greater Multiple Made of Two Digits

Leetcode Solutions

Breadth-First Search (BFS) Approach

  1. Initialize a queue and add digit1 and digit2 to it if they are not zero.
  2. If digit1 and digit2 are the same, only add one instance to the queue.
  3. While the queue is not empty: a. Dequeue the front element. b. If the number is larger than k, a multiple of k, and within the 32-bit signed integer range, return it. c. Otherwise, generate new numbers by appending digit1 and digit2 to the current number and enqueue them if they are within the 32-bit signed integer range.
  4. If no valid number is found, return -1.
UML Thumbnail

Recursive Depth-First Search (DFS) Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...