SamiTech Code
340 subscribers
127 photos
12 videos
4 files
85 links
Computer Science student and software developer focused on building impactful products, exploring AI, and solving real-world challenges with technology.
My portfolio.... sami.pro.et

“Your efforts today are your goals tomorrow.”
Download Telegram
THREE SUM: What is 3-Sum? 3-Sum = Fix one number + solve 2-Sum on the rest. We've already know 2-Sum with two pointers. So 3-Sum is just reusing that skill. Step-by-Step thinking (Human way): Step 1: Sort the array why? Enables two pointer makes duplicate skipping easy Step 2: Fix one number(loop) imagine you say: "Let me lock this number, and find two others that cancel it." if the fixed number is x, then; we need two numbers with sum = -x Step 3: Apply Two pointer for the remaining part —left pointer > next index after fixed —right pointer > end of array Now this becomes a 2-Sum problem. In the next, I'll share the Visual Example to understand clearly.👇👇
👍1🌚1
Visual Example with best clarifications: Read the👇👇👇You understand clearly about 3-Sum in easy way👌
Array: [-4, -1, 0, 1, 3, 5] #already sorted(ordered) Step 1: Fix the number -4 😎Fix means take as a constant - 4 or u can say freeze -4,Don't move it 👉🏽3-Sum goal is: a + b + c = 0 substitute -4 =a: -4 + b + c = 0 => b + c = 4 :) Target for the remaining two numbers sum = 4 Step 2: Choose where b and c can come from: We mustn't reuse -4 , so we search to the right👇 [-4 | -1, 0, 1, 3, 5]
↑ ↑ ↑ ↑ ↑ now pointer is doing this: left = -1, right = 5. then -1 + 5 = 4 :- b = -1 & c = 5 Step 4: Build the triplet: and don't forget the fixed number😀-4 => -4 + (-1) + 5 = 0 👏 Valid triplet found: (-4, -1, 5) Step 5: What happen next? After then finding a valid pair: -move both pointer: means the left to the right and the right to the left at the same time. & If there's duplicate skip New pointers: left = 0, right = 3. 0 + 3 !=4(target value). So since Sum < target move the left to the right. 1 + 3 = 4 👏Again a valid triplet found: (-4, 1, 3) keep in mind: if left and right crossed each others stop the condition. (left = 3 then right = 1)CROSSED CONDITIONS⚠️ FINAL RESULT FOR FIXED -4 Valid triplet: (-4, -1, 5) & (-4, 1, 3) Generally: 3-Sum = Freeze one number → solve a 2-sum problem beside it.

I HOPE YOU UNDERSTAND THE LOGIC OF 3-SUM😄
Implementation of 3-Sum:
Don't forget about two pointer👌 In simple the program is talks about fixing (keep constant each elements if it's true and find sum of other two values that equal to target. Therefore, fixed value -4 and -1. here algorithm say this's VALID TRIPLET but for others since they're not equal to their target value.

👉🏽the algorithm said hey, for 0, 1, 3, 5 I don't have any idea, since these haven't valid triplet, so I don't talk about the😁
Guys I hate class😏
Just we went to class but no teacher.
He said am coming but nothing happend we waited him about 30 minute.

Now am in my dorm.
..what do u think🤔
if he said now I'm in class but there's no anyone. I need all of u to back to class early😔
😢1
Good Morning Friends🌅
👍1
4️⃣ SUM: On Loading... That's similar with 3️⃣ SUM. Just only on small d/c.🕒
Keep point: 4️⃣ SUM Four Sum = Fix two numbers + solve two-Sum with two pointers. a + b + c + d = target This's only new idea but the other is as it's.
What do u think? Three Sum has
Anonymous Quiz
25%
one loop
56%
two loop
19%
Amn't Sure
😁21
Guys, I thought as long as we learn DSA. It's good to learn Python libraries.
Therefore we need your vote🗳
Anonymous Quiz
82%
Yes, we'll start Python libraries
6%
No, we can't learn them together
12%
I don't have any idea
And then guys good night

tommorow there is some gift for u🎁
I will share in this channel...stay tuned and Stay focus on. U don't have to lose this opportunity👌
🥰2
Good Morning🙋
Hey everyones are u ready for the challenges😂😂😂
Now am gonna post so pls don't lose this opportunity. Keep in mind: After 5 minute it gonna expired so try ur best before that. About 5 minute left......
This is the challenge Don't lose

❤️❤️❤️❤️I wish for all of u BEST CHANCE😄😄😄
🎉🎉🎉5 MINUTE IS UR CHANCE💪💪💪

At the first and the last fill out the numbers hidden
You have 6 minute

It gonna expired 😍😍😍
Try ur best
And please don't forget If u get
🔥1
Am gonna start NUMPY. What do u think. Your vote is needed.
Anonymous Quiz
75%
Yup, go a head
19%
No, I don't care
6%
Amn't understand