Eid Mubarak ma people β€οΈ
Wishing all my Muslim friends peace, happiness, and countless blessings on this beautiful day ππ€
May your prayers be accepted and your hearts be filled with joy
Wishing all my Muslim friends peace, happiness, and countless blessings on this beautiful day ππ€
May your prayers be accepted and your hearts be filled with joy
β‘4β€2
This summer, Iβm continuing my Competitive Programming journey with more consistency and focus
Iβll be sharing:
β’ My LeetCode progress
β’ Codeforce problems & contests
β’ DSA concepts I learn
β’ Struggles, mistakes, and improvements along the way
The goal is simple improve step by step and become a better problem solver every day π»
If youβre also learning CP or DSA, feel free to join the journey.
Iβll be sharing:
β’ My LeetCode progress
β’ Codeforce problems & contests
β’ DSA concepts I learn
β’ Struggles, mistakes, and improvements along the way
The goal is simple improve step by step and become a better problem solver every day π»
If youβre also learning CP or DSA, feel free to join the journey.
β€6π1
Grokking_Algorithms.pdf
6.2 MB
This book is good start as beginner read and understand one algorithm or data structure then do easy then medium then hard problems from leetcode or codeforce
π₯6
πTwo Sum Problem
I traverse the array one by one and for each element I calculate the complement (target β current value). I store the values I have seen in a dictionary and check if the complement already exists.
If it exists, it means those two numbers add up to the target.
My main confusion was not the logic, but the return part the problem asks for indices, not the actual values.
I traverse the array one by one and for each element I calculate the complement (target β current value). I store the values I have seen in a dictionary and check if the complement already exists.
If it exists, it means those two numbers add up to the target.
My main confusion was not the logic, but the return part the problem asks for indices, not the actual values.
π4
If you want to start learning DSA from the beginning, I recommend this NeetCode course. It explains the basics step by step and is good for beginners in competitive programming and problem solving
β€6
Contains Duplicate using a simple idea of storing seen values in a dictionary while traversing the array.
For each number, I check if I have already seen it. If yes, I return True because a duplicate exists. If not, I store it and continue. If the loop finishes without finding any repeated value, I return False.
My main mistake was in the logic flow I was returning False too early inside the loop, and I also forgot that I should check the actual values, not just the indices.
For each number, I check if I have already seen it. If yes, I return True because a duplicate exists. If not, I store it and continue. If the loop finishes without finding any repeated value, I return False.
My main mistake was in the logic flow I was returning False too early inside the loop, and I also forgot that I should check the actual values, not just the indices.
β€3
Valid Anagram using two different approaches.
First, I compared both strings by sorting them and checking if the sorted versions are equal. If they match, it means both strings contain the same characters in the same frequency.
In the second approach, I first checked if the lengths are equal. If they are not equal, I immediately return False. Otherwise, I compare the sorted strings.
My understanding is that both solutions are correct, but adding the length check helps avoid unnecessary work when the strings are clearly not anagrams.
First, I compared both strings by sorting them and checking if the sorted versions are equal. If they match, it means both strings contain the same characters in the same frequency.
In the second approach, I first checked if the lengths are equal. If they are not equal, I immediately return False. Otherwise, I compare the sorted strings.
My understanding is that both solutions are correct, but adding the length check helps avoid unnecessary work when the strings are clearly not anagrams.
β€3
Group Anagrams
I used a dictionary and grouped words by sorting each word to create a key. Words with the same sorted key are grouped together.
My main mistake was not realizing early that the sorted word should be used as the key, and I was a bit confused about converting the sorted list into a string and building the groups correctly.
Finally, I understood that anagrams become identical after sorting, so we can group them using that idea.
I used a dictionary and grouped words by sorting each word to create a key. Words with the same sorted key are grouped together.
My main mistake was not realizing early that the sorted word should be used as the key, and I was a bit confused about converting the sorted list into a string and building the groups correctly.
Finally, I understood that anagrams become identical after sorting, so we can group them using that idea.
β€4
Today feels like April Foolβs Day π
What is happening with our teacher?
That OOP exam was something else. I donβt even know what to say about the result it really wasnβt me π
What is happening with our teacher?
That OOP exam was something else. I donβt even know what to say about the result it really wasnβt me π
π6
Good morning guys βοΈ
I have a question for you all π
Do you learn for yourself, your future, and your dreams or mainly to make your family happy and proud?
Tell me your thoughts π
I have a question for you all π
Do you learn for yourself, your future, and your dreams or mainly to make your family happy and proud?
Tell me your thoughts π
π€·ββ3π1
Top K Frequent Elements
I used a dictionary to count how many times each number appears in the array. Then I sorted the frequency pairs in descending order and selected the top k frequent elements.
My main confusion was understanding how to sort the dictionary using the frequency values instead of the keys, especially the part with
I also needed time to fully understand how result.items() becomes (number, result) pairs during sorting.
This problem helped me better understand frequency maps and Top K patterns in problem solving.
I used a dictionary to count how many times each number appears in the array. Then I sorted the frequency pairs in descending order and selected the top k frequent elements.
My main confusion was understanding how to sort the dictionary using the frequency values instead of the keys, especially the part with
lambda x: x[1]
I also needed time to fully understand how result.items() becomes (number, result) pairs during sorting.
This problem helped me better understand frequency maps and Top K patterns in problem solving.
β€3
Valid Palindrome
The idea is to first normalize the string by converting it to lowercase and removing all non-alphanumeric characters, then check if it reads the same forward and backward.
My main mistake was not clearly understanding how to properly clean the string, especially removing symbols and spaces. I also initially overcomplicated it using unnecessary loops.
In the end, I learned that the most important step is preprocessing the string correctly before doing the palindrome check.
The idea is to first normalize the string by converting it to lowercase and removing all non-alphanumeric characters, then check if it reads the same forward and backward.
My main mistake was not clearly understanding how to properly clean the string, especially removing symbols and spaces. I also initially overcomplicated it using unnecessary loops.
In the end, I learned that the most important step is preprocessing the string correctly before doing the palindrome check.
β€5
Forwarded from Chapi Dev Talks
PSG Vs Arsenal
Who is going to win?
Comment the score and if arsenal loses the correct predictions I will give him prize πππ
Who is going to win?
Comment the score and if arsenal loses the correct predictions I will give him prize πππ
π3β€1
The idea is to encode a list of strings into one string using
then decode it back by reading the length first and extracting each word.
My mistake was mixing the logic in decode I tried to process the word while still searching for
which caused errors. I learned that decoding must follow a clear order find # read length, extract word, then move forward.
length#word
then decode it back by reading the length first and extracting each word.
My mistake was mixing the logic in decode I tried to process the word while still searching for
#
which caused errors. I learned that decoding must follow a clear order find # read length, extract word, then move forward.