Question

Build a brute force approach in Python for the following problem. Given two sequences of vowels,...

Build a brute force approach in Python for the following problem.

Given two sequences of vowels, find the length of longest subsequence present in both of them.

NOTE: A subsequence is a sequence that appears in the same order, but not necessarily contiguous. For example, “aei”, “aeo”, “eio”, “aiu”, ... are subsequences of “aeiou”.

Sample Input 1:

aeiou aiu

Sample Output 1:

3

Sample Input 2:

uieiai uueuouiaua

Sample Output 2:

4

Sample Input 3:

uuuuouueea euooooe

Sample Output 3:

3

Sample Input 4:

aeeeuu ieoouu

Sample Output 4:

3

Sample Input 5:

ieiaeoeee oaoai

Sample Output 5:

2

Sample Input 6:

oiaioieie eoiuueaea

Sample Output 6:

4

Sample Input 7:

uoaeuou ioooo

Sample Output 7:

2

Sample Input 8:

uaoaoaao iaeeo

Sample Output 8:

2

Sample Input 9:

uaieiaiae ieoueoiai

Sample Output 9:

5

Sample Input 10:

eaueaiu ioaaoueee

Sample Output 10:

3

test using stdin → stdout

Homework Answers

Answer #1

Code

'''using bruteforce it can be solved by both recursive or iterative method
Here,recursion method has been used'''
def res(b,c,d,e):
        if d==0 or e==0: #empty string
                return 0
        if b[d-1]==c[e-1]:
                return 1 + res(b,c,d-1,e-1)
        else:
                 return max(res(b,c,d, e-1), res(b,c,d-1, e))

a=input() #get the input
b,c=a.split(" ") 
d=len(b) # length of first input
e=len(c) #length of second input

v=res(b,c,d,e) #call the function and store it in variable v

print(v)  # print the result




      

Terminal Work

.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
python If a number num1 divides another number num2 evenly then num1 is a divisor of...
python If a number num1 divides another number num2 evenly then num1 is a divisor of num2. For example, 2 is a divisor of 2, 4, 6, 8, but 2 is not a divisor of 1, 3, 5, 7, 9, 11, 13. Write a function named count_divisors(m,n) that works as follows. Input: the function takes two integer arguments m and n Process: the function asks the user to enter numbers (positive or negative), and counts the total number of inputs...
write a python program that include a function named activity_selection() and take in two arguments, first...
write a python program that include a function named activity_selection() and take in two arguments, first one would be the number of tasks and the second argument would be a list of activities. Each activity would have an activity number, start time and finish time. Example activity_selection input and output: activity_selection (11, [[1, 1, 4 ], [2, 3, 5], [3, 0, 6], [4, 5, 7], [5, 3, 9], [6, 5, 9],[7, 6, 10], [ 8, 8, 11], [ 9, 8,...
Divide-and-Conquer technique is famous for providing O(n log n) solutions for problems with O(n2) straight forward...
Divide-and-Conquer technique is famous for providing O(n log n) solutions for problems with O(n2) straight forward solutions. One of those problems is the “Maximum Subarray Sum” or “Maximum Value Contiguous Subsequence": Given a sequence of n numbers A[0 ... n-1], give an algorithm for finding a contiguous subsequence A[i ... j], for which the sum of elements in this subsequence is the maximum we can get by choosing different i or j.   For example: the maximum subarray sum for the...
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
We are given an array A of size n containing n positive and negative integers (the...
We are given an array A of size n containing n positive and negative integers (the array is indexed starting from 0). Our goal is to find two indices i and j such that 0 ≤ i ≤ j ≤ n and Pk=j k=i A[k] is maximized. Input sequence: [2, -4, 1, 9, -6, 7, -3] Output: [1, 9, -6, 7] or i = 2 and j = 5 Input sequence: [1, 2, 3, 4, 5, 6, -3] Output: [1,...
Pinky and The Brain are great friends. They like to play games with numbers. This time,...
Pinky and The Brain are great friends. They like to play games with numbers. This time, Pinky has given The Brain a list of numbers and given him the task of determining if it is possible to choose a subset of them such that they sum is equal to another given number. Build an algorithm using dynamic programming to help The Brain with his problem. INPUT The first line corresponds to N, the amount of numbers given by Pinky The...
# Python Given the list values = [], write code that fills the list with each...
# Python Given the list values = [], write code that fills the list with each set of numbers below. Note: use loops if it is necessary 1 2 3 4 5 6 7 8 9 10 0 2 4 6 8 10 12 14 16 18 20 1 4 9 16 25 36 49 64 81 100 0 0 0 0 0 0 0 0 0 0 1 4 9 16 9 7 4 9 11 0 1 0...
Suppose that a client performs an intermixed sequence of Stack push and pop operations. The push...
Suppose that a client performs an intermixed sequence of Stack push and pop operations. The push operations put the integers 0 through 9 in order onto the Stack. That is, the following operations must appear in this order with any number of pop operations in between: push(0), push(1), …, push(8), push(9). Each pop operation pops the top item off the Stack and prints the return value. Determine if each of the following sequences can or cannot be a result of...
Java please. Given a sequence of unsorted numbers, determine how badly out of order they are....
Java please. Given a sequence of unsorted numbers, determine how badly out of order they are. Write a program that, for any given sequence of unique natural numbers, will compute the 'distance' between that original ordering and the same set of numbers sorted in ascending order. The distance should be computed by calculating how far displaced each number is in the original ordering from its correct location in the sorted list and summing those results. For instance, given the list...
The following data was collected by measuring the force load acting on a small area of...
The following data was collected by measuring the force load acting on a small area of a beam under repeated “fixed” conditions: Reading Output (N) Reading Output (N) 1 923 6 916 2 932 7 927 3 908 8 931 4 932 9 926 5 919 10 923 Plot the data using Python with appropriate labels for the x axis, y axis, and plot title. Be sure to comment your Python code. Determine the systematic error and maximum random error...