Menu
Coddy logo textTech

Pattern Finder

Part of the Fundamentals section of Coddy's Rust journey — lesson 74 of 75.

challenge icon

Challenge

Easy

Create a program that receives two arrays of strings of size 8 and 3 respectively as input and determines if the second array appears as a pattern within the first array (in consecutive order).

A pattern exists when all elements of the second array appear together, in the same order, somewhere within the first array, like finding a substring within a string.

For example:

let arr1 = ["1", "2", "3", "4", "5", "6", "7", "8"];
let arr2 = ["3", "4", "5"];
// Should return true
let arr1 = ["5", "6", "7", "8", "9", "1", "2", "3"];
let arr2 = ["6", "8", "9"];
// Should return false (not consecutive)

Try it yourself

use std::io;

fn main() {
    let mut input_str_arr_1 = String::new();
    let mut input_str_arr_2 = String::new();
    io::stdin().read_line(&mut input_str_arr_1).unwrap();
    io::stdin().read_line(&mut input_str_arr_2).unwrap();
    let arr1: Vec<String> = input_str_arr_1.trim().split(',').map(String::from).collect();
    let arr2: Vec<String> = input_str_arr_2.trim().split(',').map(String::from).collect();
    
    let mut result = false;
    // Write your code below



    println!("{}", result);
}

All lessons in Fundamentals