Bahi 3ana problem esmo “Longest Uncomon Subsequence I “ → honi fe problem 3ana zouz…
- User
Bahi 3ana problem esmo “Longest Uncomon Subsequence I “ → honi fe problem 3ana zouz “Strings” a and b El objective enik tlwj “longest uncommon subsequcence “ between a and b , Ken 7aje kema hka mch mwjoud jemla lzemik traj3 “-1”
Q- bahi 3ana defintion honi ? chnowa blhii → ya sedik the definition of “uncommon subsequence” hiya subsequence → fe be7tho yukon the “subsequence” mwjoud ken fe w7ed fihom
Q- tw n7kibik tl5esli chnowa fehmt m8ir “mtghos “fe solution Q- ame ne7bik fe tunisi oky
Bahi Amir, tw nhab tl5eslik el problem mch bel 7ell, ken t7eb el fekra bch t3refha men loul.
El problem ykoun 3andek zouz strings "a" w "b" w enti t7awel tlwj "longest uncommon subsequence" binethom. L' uncommon subsequence hia m3naha jemla nجم tkoun subsequence men a wla b ama mech mwjoud fi zouzhom, mech tkoun f a w fi b kif kif.
Besh n5alleha bsita:
- Ki tji tlwj longest uncommon subsequence, tfakr chnowa el subsequence li mawjouda ken fi wahda mel strings w mech fel string el thanya.
- L7alet el ekstremiya: ken el zouz strings ykounou kif kif, mta3nejch uncommon subsequence binethom. Houni trajje3
-1.
Solution bch tkoun simple w mch metghish barch:
- Twakna: ken el string "a" w "b" mech kif kif, the longest uncommon subsequence hia string el el akber fihom, chniya el ekber? Le string li fiha a9tar toul.
- Ken a w b kif kif, el uncommon subsequence mech mawjouda w trajje3
-1.
El fekra ki thab tlwj l jemla el taoula eli mch mawjouda fi el deux strings kif kif.
Q- bhi awll seoul : what is the input & output format here ?
Bahi the input bash yukon two strings Input : s1 string , s2 : string Output : x int
Q- oky now can you go through an example oky :
El input a = “aba” a laer r howa “cdc”
Bahi ntsewer ,bdwa be naive solution n5tro w7ed men string a wle b oky (ani bsh nt5tar ) the string a oky
→ ba3idd : t7well degenerate all the subsequnce from the choising one (a )
“Aba”
Here are all the subsequences of "aba": "" (empty string) "a" "b" "a" "ab" "aa" "ba" "aba" Q- donc b3ed t7well fe kol subsequence tlwj est ce que mwjoud wle oky (ken mch wjoud )
Ken mwjoud donc just compare it with the reference variable oky
Q- bahii honi el thinking process
“Abstract “ barsh Mch formal oky (using mathematical notations ) Naive solution not optimzied Q- i know this fact :
Q- but stay with me we will go into more detail later Q- just from now judge only my first thinking process and give me a honest feabback oky right
- Assistant
أهلاً بيك! واضح إنك فهمت المبدأ الأساسي للمشكلة وبدأت في التفكير بالطريقة الصحيحة. خليني نراجع معاك الخطوات الي قمت بيها ونعطيك بعض الملاحظات:
مراجعة فكرتك:
-
تعريف "Uncommon Subsequence":
- صحيح إن "الـ Uncommon Subsequence" هي عبارة عن سلسلة فرعية تكون موجودة في واحدة من السلسلتين a أو b ومش موجودة في الثانية.
-
الحالة الخاصة:
-