Oky honi : 3ana String “S” : n7ebo ntl3o the longest “substring” between two equal…
- User
Oky honi : 3ana String “S” : n7ebo ntl3o the longest “substring” between two equal characters , excluding the two characters . if there is no such substring return -1 oky A substring : is a contigous sequencr of characters within a string Ken m9enech jemla nraj3o “-1” oky
S =”abca” —> honi the upper case and lower case mt3 substring hiya → index = 0 → index = 3 Donc the longest substring honi hiya (3-0-1) // the upper case in exculded it oky
Q- bahii aw fekra jetni fe mo5ii Q- be7okem n7na n7ebo n maximuziw the length mt3 longest substring betwen two equal string :
Q- netswer a7sen solution enou : ntlw 3le min lower bound and max upper bound Wen el upper bound and lower bound el zoz 3andhom nefes el value oky
Q- be 7okem enou the length mt3 input string honi wa4e7 … netswer enou two pointer technique tnjm tkon el 7all oky
Q- kefh enik t3ml “initiate” le two pointers left and right oky : → “i” and “j” First oky :
Q- where the left pointer start from the beginner of the string Q- and the right one start start from the top right of the string
Q- b3ed n93do nlwjo 3le awll “equality” betwen the two values that left and right pointer point to oky
Q- m3nha n9s3ed lnwjoo 3le awll s[l]==s[r] : oky
Q- ken 9enha donc we return difference btwen the two oky
R-l -1 oky and break the while loop
Q- else return -1
Q- so you are my mentor now Q- you need to give me feedback about my approch Q- and how can i translate it into a working solution oky
- Assistant