SamiTech Code
339 subscribers
129 photos
12 videos
4 files
86 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
Afternoon guys: in this morning since there was a class I didn't share for u DSA related topics. Btw the class was so good, it's intersting course.👇
Data communication&Networking

Just now am about to eat my lunch so, let's eat together😆

👉For more info stay tuned with me
🍌2
And guys Since our learning journey is related with this channel.

It's intersting to join also and she post daily problem on this channel.
https://t.me/A_StepForward
It' all about DSA. So let's grow together.⚡️
The Two-Pointers Technique is a simple yet powerful strategy where you use two indices (pointers) that traverse a data structure - such as an array, list, or string - either toward each other or in the same direction to solve problems more efficiently

Two pointers is really an easy and effective technique that is typically used for: Two Sum in Sorted Arrays, Closest Two Sum, Three Sum, Four Sum, Trapping Rain Water and many other popular interview questions. we'll see them one by one👇
👍1
Problem:
👉 Given an integer array, find two elements whose sum is closest to 0. arr = [1, -3, 2, -1, 4]
Key points:

Array may have negative and positive numbers,
We want the minimum absolute sum,
Use Two Pointer after sorting. Let's think of it first how to handle this problem🤔
My pc just makes me so angry
Just I opened Vscode and still now it's not responding.
And still now is on the loading😡, ....whatever now Am trying to use code editor on the online.. However As i open the the software it's closing by it self....😔
There is more conflict b/n the system right?🤔

May be if u have some tips to solve this kind of problem u can tell me
SamiTech Code
Photo
Questions: What're the following statement line doing👇 1.closest_sum = float('inf') #what happens if we remove #inf 2. pair = (None, None) 3. if abs(current_sum) < abs(closest_sum) 4. pair = (arr[left], arr[right]) Take u'r time & Try to think of it🤔 understanding this concept takes u to the next step💪🏻 AND YOUR ANSWER IN THE COMMENT SECTION👌
SamiTech Code pinned «Thinking Problem (Two Pointer – Human Way): You're given this sorted array: [2, 3, 5, 7, 11, 15], target sum = 10 …»
SamiTech Code pinned «Questions: What're the following statement line doing👇 1.closest_sum = float('inf') #what happens if we remove #inf …»
Good Night Family🛌
Good morning guys
In this morning I was...
Anonymous Quiz
29%
Doing sport💪
29%
Sleeping😴
41%
Nothing
👍1
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