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
Intro to JAVA Problem 1: Summing It Up Write a program, which takes two distinct integers...
Intro to JAVA Problem 1: Summing It Up Write a program, which takes two distinct integers separated by space as input and prints the sum of all the integers between them, including the two given numbers. Note that the numbers can appear in either order. You may assume that both numbers are between –10, 000 and 10, 000. For example, if the input is as follows: 10 4 the output should be 49, since 10+9+8+7+6+5+4=49. Similarly, if the input is...
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...
{- Alexa loves movies and maintains a list of negative and/or positive integer ratings for the...
{- Alexa loves movies and maintains a list of negative and/or positive integer ratings for the n movies in her collection. She's getting ready for a film festival and wants to choose some subsequence of movies from her collection to bring such that the following conditions are satisfied: The collective sum of their ratings is maximal. She must go through her list in order and cannot skip more than one movie in a row. In other words, she cannot skip...
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,...
2.3 Consider the data in the following two sequences AB Sequence Patient Period 1 Period 2...
2.3 Consider the data in the following two sequences AB Sequence Patient Period 1 Period 2 1 310 270 2 310 260 3 370 300 4 410 390 5 250 210 6 380 350 7 330 365 8 310 320 9 340 275 10 365 285 11 280 330 12 345 240 13 320 310 14 330 300 BA Sequence Patient Period 1 Period 2 1 370 385 2 310 400 3 380 410 4 290 320 5 260 340...
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...
JAVA Problem 1: Summing It Up Write a program, which takes two distinct integers separated by...
JAVA Problem 1: Summing It Up Write a program, which takes two distinct integers separated by space as input and prints the sum of all the integers between them, including the two given numbers. Note that the numbers can appear in either order. You may assume that both numbers are between –10, 000 and 10, 000. For example, if the input is as follows: 10 4 the output should be 49, since 10+9+8+7+6+5+4=49. Similarly, if the input is -3 10...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT