Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Scala Programming Question: Extract all indices matching a given sequence. Write a scala function findPatternIndicesInList that inputs two lists of Strings, lst and pattern. The

Scala Programming

Question: Extract all indices matching a given sequence.

Write a scala function findPatternIndicesInList that inputs two lists of Strings, lst and pattern. The goal is to find all the indices in lst such that the list pattern occurs in lst at these indices.

Example 1

lst is List("quick", "brown", "fox", "quick", "brown", "dog") and pattern is List("quick", "brown"). Code should return: List(0, 3). This is because starting at positions 0 (the very beginning) and 3 (the 4th element), we have occurrences of the pattern pattern: List("quick", "brown").

Ex. 2

lst is the list List("a", "b", "a", "c", "a", "a", "b") and pattern is List("a", "b"). Your code should return List(0, 5) since starting at indices 0, 5 in lst, we have an occurrence of the patterrn pattern.

Ex. 3

lst is the list List("a", "b", "a", "c", "a", "a", "b") and pattern is List("a"). Your code should return List(0, 2, 4, 5).

Ex. 4

lst is the list List("a", "b", "a", "c", "a", "a", "b") and pattern is List("a", "b", "c"). Your code should return the empty list since there is no occurrence of the patterrn List("a", "b", "c") in the original list.

Hint: Please use the function extractSubList you wrote for the previous problem and compare lists using the == operator.

In [ ]:

 
def findPatternIndicesInList(lst: List[String], pat: List[String]): List[Int] = {
 // YOUR CODE HERE
 ???
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions

Question

what is a peer Group? Importance?

Answered: 1 week ago

Question

6. Explain how to train managers to coach employees.

Answered: 1 week ago

Question

5. Tell how job experiences can be used for skill development.

Answered: 1 week ago