Description
Solutions
Check Pattern Presence
🤘 INTERN

tomtom's note: Feel free to check out the source image below for the original problem statement :)

Imagine you're given a string of digits called panel and an array of strings called codes. Each string in the codes array is made up of digits and follows a specific format: "", where both the index and pattern are composed of at least one digit. Since there are several possible ways to split the code into the index and pattern, we'll explore all of them, starting with the smallest index length.

For example, if the code is "1324", the possible splits would be:

  • split-case 1: index = "1" and pattern = "324"
  • split-case 2: index = "13" and pattern = "24"
  • split-case 3: index = "132" and pattern = "4"
  • For each code in the codes array, and for every split-case of this code, we'll check whether the pattern appears at the specified index in the panel string. You'll receive a string array as a result, where each element will either be the pattern (if it’s found in the panel at the correct position) or "not found" if it isn’t.

    Don’t worry about making your solution the fastest possible, but it should work efficiently enough given the size of the inputs.

    ⋆˙˳𓂃𓂃𓂃𓊝𓂃𓂃Credit to Charlotte𓂃𓂃𓂃˙˳⋆

    Example 1:

    Input:  board = "2311453915", keys = ["0211", "639"]
    Output: ["not found", "11", "not found", "39", "not found"]
    Explanation:
    Once upon a time, in the land of digits, there was a string called panel and a group of secret codes known as codes. Each code was a puzzle, with two parts hidden within: an index and a pattern. The task was to discover if the pattern appeared in the panel at the exact spot indicated by the index. To uncover this, we had to explore all possible ways to split each code, like peeling back layers of a mystery. Let’s begin with the first code, "0211." There were three different ways to split it: In the first split-case, we tried index "0" and pattern "211." We searched for "211" starting from the 0th position in the panel, but the panel revealed "231," not our pattern. Sadly, this wasn’t the correct code. The answer: "not found." Next, we tried index "02" and pattern "11." To our delight, the panel whispered back "11" at the right spot. This was the correct code! The answer: "11." Lastly, we explored index "021" with pattern "1." But the panel had nothing to offer at such a distant place—it was simply too far. The answer: "not found." Then came the second code, "639," with two possibilities: First, we tried index "6" and pattern "39." The panel responded perfectly, showing "39" right where we hoped. The code was valid! The answer: "39." Finally, we tried index "63" with pattern "9," but the panel’s digits didn’t stretch that far. Once again, the answer was "not found." And so, the results of this little adventure were a collection of answers: ["not found", "11", "not found", "39", "not found"], each reflecting the success or failure of our code-breaking journey.
    Constraints:
      • 1 ≤ panel.length ≤ 103
    Thumbnail 0
    Thumbnail 1
    Testcase

    Result
    Case 1

    input:

    output: