Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    753 - Cracking the Safe\.

    Hard

    There is a safe protected by a password. The password is a sequence of n digits where each digit can be in the range [0, k - 1].

    The safe has a peculiar way of checking the password. When you enter in a sequence, it checks the most recent n digits that were entered each time you type a digit.

    • For example, the correct password is "345" and you enter in "012345":

    Return any string of minimum length that will unlock the safe at some point of entering it.

    Example 1:

    Input: n = 1, k = 2

    Output: "10"

    Explanation: The password is a single digit, so enter each digit. "01" would also unlock the safe.

    Example 2:

    Input: n = 2, k = 2

    Output: "01100"

    Explanation: For each possible password:

    • "00" is typed in starting from the 4<sup>th</sup> digit.

    • "01" is typed in starting from the 1<sup>st</sup> digit.

    • "10" is typed in starting from the 3<sup>rd</sup> digit.

    • "11" is typed in starting from the 2<sup>nd</sup> digit.

    Thus "01100" will unlock the safe. "01100", "10011", and "11001" would also unlock the safe.

    Constraints:

    • 1 &lt;= n &lt;= 4

    • 1 &lt;= k &lt;= 10

    • <code>1 <= k<sup>n</sup><= 4096</code>

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final String crackSafe(Integer n, Integer k)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait