Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Codewriting Every so-often on Codesignal a user tries to submit a duplicate solution they copied from someone else. Generally these are pretty easy to detect

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Codewriting Every so-often on Codesignal a user tries to submit a duplicate solution they copied from someone else. Generally these are pretty easy to detect and block. Hawever, it gets trickier when you have a duplicate soluton with some variables renamed to avoid getting caught The cheating usually happens as follows: in a text edtor the "Find and replace" function is apphed to all occurrences of Isome vanable name A that " consists of lethers, digits, or underscores, and starts with a non-digit character (since irs a variable name), to change it to some other variable name s that fulfilis the same constraints If would appear that after applying this "Find and replace" procedure multiple times it would be impossibie to detect duplicates. but this isnt the case. Your goal is to implement an alggrithm that compares two code snipgets and determines whether the last of them could be produced from the first one using the abcive.described approach Note. Here is a formal delintion of how "Find and replace" function works. When searching tor string a to replace all of is occurrences in string s with string I, it first finds the lelimost occurrence of A in 5 . Then it replaces this occurence of A with s. Then itrepeats the above procedure tor the suffix of 5 which stars immediately atter the last character ct the inserted copy of in The process repeats untit the remaining suffix contains no occurrences of A Example - For codes-[-defisevensun(a,b):=,0] and codez,=["defisevensum(suarand,1,samaav,2):7,retern(suarand1+sumand2)2o] the oifpot should be selut ion(coded, toder) - true For code1=["defisevensum(a,b):",return(a+b)201] and codez-[-defisevensum(summand1,sunmand2):",return(summand1+sumand2)2=0] the output should be solution(code1, codez) - true All occurrences of a are replaced with sumand 1 , and all occurrences of b are replaced with - For codes-["functioniseven-sum(a,b)[".return(a+b)2=0;" and codez-["functionisevensum(a,b)[".return(a+b)x2t-1;, the output should be solut ion(codel, codez) - false - For codel - I"def foo(a, b):", codet=["deffoo(a,b)::,returna+a] and codez-["deffoo(b,a):",returnb+b]. the output should be solution(code1, code2) - true It is possible first to replace all occurrences of b to c, then to replace all a s to b, and then all occurrences of c to a Input/Output - [execution time limit] 3 seconds (java) - [input] array.string code1 Guaranteed constraints: 1codel.length600code1[1].Tength100 - [input] array,string code2 Guaranteed constraints: 1codez.1ength600codez[i].length100 - [output] boolean It is possible first to replace all occurrences of b to c, then to replace all a s to b and then all occurrences of c to a nput/Output - [execution time limit] 3 seconds (java) - [input] array.string code1 Guaranteed constraints: 1code1.Tength600code1[i].length100 - [input] array.string code2 Guaranteed constraints. 1codez.Tength600codez[i].Tength100 - [output] boolean can be obtained from codel using zero or more "Find and replace* operations, false otherwise. [Java] Syntax Tips If Prints help sessage to the console 1f meturns a string II. I/ clobals declared here will cause a cospilation error. If declare variables inside the function instead! string helloworld (string naze) f Systes, out, print ln( "This prints to the console when you run rests"): return "Hello," + nane; Codewriting Every so-often on Codesignal a user tries to submit a duplicate solution they copied from someone else. Generally these are pretty easy to detect and block. Hawever, it gets trickier when you have a duplicate soluton with some variables renamed to avoid getting caught The cheating usually happens as follows: in a text edtor the "Find and replace" function is apphed to all occurrences of Isome vanable name A that " consists of lethers, digits, or underscores, and starts with a non-digit character (since irs a variable name), to change it to some other variable name s that fulfilis the same constraints If would appear that after applying this "Find and replace" procedure multiple times it would be impossibie to detect duplicates. but this isnt the case. Your goal is to implement an alggrithm that compares two code snipgets and determines whether the last of them could be produced from the first one using the abcive.described approach Note. Here is a formal delintion of how "Find and replace" function works. When searching tor string a to replace all of is occurrences in string s with string I, it first finds the lelimost occurrence of A in 5 . Then it replaces this occurence of A with s. Then itrepeats the above procedure tor the suffix of 5 which stars immediately atter the last character ct the inserted copy of in The process repeats untit the remaining suffix contains no occurrences of A Example - For codes-[-defisevensun(a,b):=,0] and codez,=["defisevensum(suarand,1,samaav,2):7,retern(suarand1+sumand2)2o] the oifpot should be selut ion(coded, toder) - true For code1=["defisevensum(a,b):",return(a+b)201] and codez-[-defisevensum(summand1,sunmand2):",return(summand1+sumand2)2=0] the output should be solution(code1, codez) - true All occurrences of a are replaced with sumand 1 , and all occurrences of b are replaced with - For codes-["functioniseven-sum(a,b)[".return(a+b)2=0;" and codez-["functionisevensum(a,b)[".return(a+b)x2t-1;, the output should be solut ion(codel, codez) - false - For codel - I"def foo(a, b):", codet=["deffoo(a,b)::,returna+a] and codez-["deffoo(b,a):",returnb+b]. the output should be solution(code1, code2) - true It is possible first to replace all occurrences of b to c, then to replace all a s to b, and then all occurrences of c to a Input/Output - [execution time limit] 3 seconds (java) - [input] array.string code1 Guaranteed constraints: 1codel.length600code1[1].Tength100 - [input] array,string code2 Guaranteed constraints: 1codez.1ength600codez[i].length100 - [output] boolean It is possible first to replace all occurrences of b to c, then to replace all a s to b and then all occurrences of c to a nput/Output - [execution time limit] 3 seconds (java) - [input] array.string code1 Guaranteed constraints: 1code1.Tength600code1[i].length100 - [input] array.string code2 Guaranteed constraints. 1codez.Tength600codez[i].Tength100 - [output] boolean can be obtained from codel using zero or more "Find and replace* operations, false otherwise. [Java] Syntax Tips If Prints help sessage to the console 1f meturns a string II. I/ clobals declared here will cause a cospilation error. If declare variables inside the function instead! string helloworld (string naze) f Systes, out, print ln( "This prints to the console when you run rests"): return "Hello," + nane

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_2

Step: 3

blur-text-image_3

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

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

More Books

Students also viewed these Databases questions

Question

=+c) What is the response?

Answered: 1 week ago