Part A Write a function: string_section (s1, s2) The function gets two strings s1,s2 as parameters. The strings are made

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
correctanswer
Posts: 43759
Joined: Sat Aug 07, 2021 7:38 am

Part A Write a function: string_section (s1, s2) The function gets two strings s1,s2 as parameters. The strings are made

Post by correctanswer »

Part A Write A Function String Section S1 S2 The Function Gets Two Strings S1 S2 As Parameters The Strings Are Made 1
Part A Write A Function String Section S1 S2 The Function Gets Two Strings S1 S2 As Parameters The Strings Are Made 1 (127.14 KiB) Viewed 81 times
Part A Write a function: string_section (s1, s2) The function gets two strings s1,s2 as parameters. The strings are made of English letters and are sorted alphabetically from left to right. The function returns a sorted string that includes only common letters from s1 and s2. Each letter appears in the result as many times as it appears in both strings. Time complexity requirement: O(n1+n2) n1 = len(s1), n2 = len(s2). Examples: s1 s2 return 'cde' 'cde' 'abcdefg' 'booooozz' 'Ozzz' 'ozz' 'abcd' 'efgh' 'hhhh' 'hhhh' 'hhhh' Part B Write a program that gets as input two strings from the user, one after the other. The program prints the result of string_section (s1,s2) by calling the function with the input strings. Notes: ● Strings s1,s2 are composed of lowercase English letters only. In Python, you can use: 'a' < 'b' True 'c'> 'd' → False ● Do not use any input prompts or unnecessary prints. Try to write efficient code. Avoid unnecessary loops and statements. Both parts of the question should be in the file hw4q1.py.
Register for solutions, replies, and use board search function. Answer Happy Forum is an archive of questions covering all technical subjects across the Internet.
Post Reply