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
N7eb n9ollek el thinking process mte3ek juste bdeytu s7i7a w mcha fel sens s7i7!
- Assistant
Mabruk Amir! 🎉
7kayet el Thinking Process mte3ek s7i7a w mcha mzyan!
1. Points Positifs:
- Naive Approach: Bdit b approach ta3 generation lel subsequences w hetha step by step mouchkla tawsselt lih solution.
- Fhemt el Concept: Fhemt eli el longest uncommon subsequence ykoun string kamel fihom wahed w mech fih el thanya.
- Simplification: 3raft bch t simplifi el problem bel observation eli ken strings different, el akbar tkun longest.
2. Confirmation el Optimal Solution: El solution mte3ek s7i7a w tawki alaya b follow these steps:
-
Case 1: Ken w mech kif kif (a ≠ b), the longest uncommon subsequence hia el akbar binhom, yaani . L'legitima kif ykoun el akber ma yetfahemsh fel zouz men b3adhom, donc ykoun el string el a9tar toul howa el answer.