I will be documenting my learning journey in Data Structures and Algorithms here. I will be using C++ / Python / Java for this purpose.
I am trying to follow Striver's A2Z DSA Course/Sheet. It's extremely organised, starts from the fundamentals and goes on to advanced topics. I will be following this course and also supplementing it with other resources like GeeksforGeeks and LeetCode.
I hope to make a commit everyday as I learn one new thing everyday. I will be taking notes in Markdown and also include C++ files where necessary.
I hope that this public contract will keep me accountable and help me stay consistent in my learning.
- https://www.hackerrank.com/challenges/solve-me-first/problem (5 Feb 2025)
- https://www.hackerrank.com/challenges/cpp-hello-world/problem?isFullScreen=true (5 Feb 2025)
- https://www.hackerrank.com/challenges/c-tutorial-basic-data-types/problem?isFullScreen=true (5 Feb 2025)
- https://www.hackerrank.com/challenges/cpp-input-and-output/problem?isFullScreen=true (9 Feb 2025)
- https://www.hackerrank.com/challenges/c-tutorial-for-loop/problem?isFullScreen=true (12 Feb 2025)
- https://www.hackerrank.com/challenges/c-tutorial-conditional-if-else/problem?isFullScreen=true (12 Feb 2025)
- https://www.hackerrank.com/challenges/c-tutorial-functions/problem?isFullScreen=true (12 Feb 2025)
- https://www.hackerrank.com/challenges/c-tutorial-pointer/problem?isFullScreen=true
- https://www.hackerrank.com/challenges/arrays-introduction/problem?isFullScreen=true
- https://www.hackerrank.com/challenges/python-division/problem?isFullScreen=true [Python] (23 Mar 2025)
- https://www.hackerrank.com/challenges/python-loops/problem?isFullScreen=true [Python] (23 Mar 2025)
- https://www.hackerrank.com/challenges/python-arithmetic-operators/problem?isFullScreen=true [Python] (24 Mar 2025)
- https://www.hackerrank.com/challenges/python-print/problem?isFullScreen=true [Python] (24 Mar 2025)
- https://www.hackerrank.com/challenges/python-integers-come-in-all-sizes/problem?isFullScreen=true [Python] (24 Mar 2025)
- https://www.hackerrank.com/challenges/python-power-mod-power/problem?isFullScreen=true [Python] (24 March 2025)
- https://www.hackerrank.com/challenges/python-power-mod-power/problem?isFullScreen=true [Python] (24 March 2025)
- https://www.hackerrank.com/challenges/np-sum-and-prod/problem?isFullScreen=true [Python, Numpy] (25 March 2025)
- https://www.hackerrank.com/challenges/bash-tutorials---the-world-of-numbers/problem?isFullScreen=true [Bash] (28th March 2025)
- https://www.hackerrank.com/challenges/swap-case/problem?isFullScreen=true [Python, sWAP cASE] (2nd April 2025)
- https://www.hackerrank.com/challenges/whats-your-name/problem?isFullScreen=true [Python, Basic Printing] (4th April 2025)
- https://www.hackerrank.com/challenges/simple-array-sum/problem?isFullScreen=true [Array Sum] (9th Apr 2025)
- https://www.hackerrank.com/challenges/py-introduction-to-sets/problem?isFullScreen=true [Python, Sets] (10th Apr 2025)
- https://www.hackerrank.com/challenges/conditional-statements-in-c/problem?isFullScreen=true [If-Else in C] (12th Apr 2025)
- https://www.hackerrank.com/challenges/find-a-string/problem?isFullScreen=true [Sliding Window Substring Matching] (13th Apr 2025)
- Learnt how to slide a window over a string to find a substring. Created https://claude.site/artifacts/d26622f9-69ef-4dfa-90da-303be1cea047 to visualize it.
- Trying to setup
commitizen
- https://www.hackerrank.com/challenges/py-set-add/problem?isFullScreen=true (15 Apr 2025)
- Learnt
s.add()
method in set for Python.
- Learnt
- https://www.hackerrank.com/challenges/python-string-split-and-join/problem?isFullScreen=true
- Learnt about
split()
andjoin()
. I knew split which splits a string into a list (" "
is the default delimiter). Howeverjoin()
I didn't know too well."-".join(a)
wherea
is a list returns"a[0]-a[1]-a[2]...a[len(a)-1]"
- Learnt about
- https://www.hackerrank.com/challenges/python-lists/problem?isFullScreen=true [Python Lists]
- Slew of List functions like
pop
,append
,l[::-1]
,.remove
,.sort
. sort
sorts the list in-place.
- Slew of List functions like
- https://www.hackerrank.com/challenges/compare-the-triplets/problem?isFullScreen=true
- Use
zip
which iterates over tuples. - Basic
if
,elif
andelse
logic.
- Use
- https://www.hackerrank.com/challenges/bash-tutorials---a-personalized-echo/problem
- To get input in
bash
use the read command. Nice Bash Tutorial for beginners here.
- To get input in
- https://www.hackerrank.com/challenges/text-processing-cut-1/problem
cut -b <num>
gets the<num>
byte from a string.
- https://www.hackerrank.com/challenges/find-second-maximum-number-in-a-list/problem?isFullScreen=true
- Sort the list, record the highest score. Keep on looping through the list from the end and check if the current value is equal to the highest score or not, if it is then that score is not the runner up. So continue. Else the current value is not equal to the highest score, then it must be the runner up as the list has already been sorted with the
.sort()
command which sorts a list in place in Python.
- Sort the list, record the highest score. Keep on looping through the list from the end and check if the current value is equal to the highest score or not, if it is then that score is not the runner up. So continue. Else the current value is not equal to the highest score, then it must be the runner up as the list has already been sorted with the
-
https://leetcode.com/problems/concatenation-of-array/description/ (18 Mar 2025)
-
https://leetcode.com/problems/return-length-of-arguments-passed/description/ (18 Mar 2025)
-
Height Checker: https://leetcode.com/problems/height-checker/description/?envType=problem-list-v2&envId=array (18 Mar 2025)
-
https://leetcode.com/problems/display-the-first-three-rows/description/ [Pandas] (18 Mar 2025)
-
https://leetcode.com/problems/modify-columns/description/ (20th Mar 2025)
-
https://leetcode.com/problems/rename-columns/description/ [Pandas] (20th Mar 2025)
-
https://leetcode.com/problems/change-data-type/description/ [Pandas] (20th Mar 2025)
-
https://leetcode.com/problems/select-data/?envType=study-plan-v2&envId=introduction-to-pandas&lang=pythondata [Pandas] (22nd Mar 2025)
-
https://leetcode.com/problems/recyclable-and-low-fat-products/description/?envType=study-plan-v2&envId=top-sql-50 [SQL] (27th Mar 2025)
-
https://leetcode.com/problems/find-customer-referee/description/?envType=study-plan-v2&envId=top-sql-50 [SQL] (27th Mar 2025)
-
https://leetcode.com/problems/big-countries/?envType=study-plan-v2&envId=top-sql-50 [SQL] (27th Mar 2025)
-
https://leetcode.com/problems/article-views-i/description/?envType=study-plan-v2&envId=top-sql-50 [SQL] (27th Mar 2025)
-
https://leetcode.com/problems/create-a-dataframe-from-list/description/?envType=study-plan-v2&envId=introduction-to-pandas&lang=pythondata [Pandas] (29th Mar 2025)
-
https://leetcode.com/problems/get-the-size-of-a-dataframe/description/?envType=study-plan-v2&envId=introduction-to-pandas&lang=pythondata [Pandas] (29th Mar 2025)
-
https://leetcode.com/problems/create-a-new-column/description/?envType=study-plan-v2&envId=introduction-to-pandas&lang=pythondata [Pandas] (29th March 2025)
-
https://leetcode.com/problems/drop-duplicate-rows/description/?envType=study-plan-v2&envId=introduction-to-pandas&lang=pythondata [Pandas] (29th March 2025)
-
https://leetcode.com/problems/drop-missing-data/description/?envType=study-plan-v2&envId=introduction-to-pandas&lang=pythondata [Pandas] (30th March) (nice editorial)
-
https://leetcode.com/problems/check-if-the-number-is-fascinating/description/ [Hash Table, Math] (30th March 2025)
-
https://leetcode.com/problems/number-of-good-pairs/ [DSA] (31st March 2025)
-
https://leetcode.com/problems/add-two-integers/description/ [Add 2 Numbers xD] (7 Apr 2025)
-
https://leetcode.com/problems/valid-palindrome/description/ [Palindrome] (7 Apr 2025)
-
https://leetcode.com/problems/intersection-of-two-arrays/description/ [Intersection of Two Arrays] (8 Apr 2025)
-
https://leetcode.com/problems/plus-one/ [Plus One] (9 Apr 2025)
-
https://leetcode.com/problems/shuffle-the-array/description/ [Shuffle an Array] (9 Apr 2025)
-
https://leetcode.com/problems/fill-missing-data/description/?envType=study-plan-v2&envId=introduction-to-pandas&lang=pythondata [Pandas] (11 Apr 2025)
-
https://leetcode.com/problems/running-sum-of-1d-array/description/ [Running Sum of 1D Array] (15 Apr 2025)
- Did a running sum of the array.
-
https://leetcode.com/problems/sqrtx/ (15 Apr 2025)
- Did this in O(n) time. Problem is to find the square root of a number without using built in functions. Can do this with binary search and thus reduce the problem into
O(log(n))
- Did this in O(n) time. Problem is to find the square root of a number without using built in functions. Can do this with binary search and thus reduce the problem into
-
- Essentially teaches you how to use the
pd.concat()
function.concat()
allows you to glue dataframes together. Ifaxis=0
it does a row wise concatenation (increase the height of the dataframe) and ifaxis=1
, it does a column wise concatenation (increase the width of the dataframe). Also supportsjoin
etc. i.e.inner
andouter
. Great short medium article here.
- Essentially teaches you how to use the
-
- Method Chaining. Filter, sort the df by weight using
sort_values(by='col_name')
and then get the necessary column.
- Method Chaining. Filter, sort the df by weight using
-
https://leetcode.com/problems/add-digits/description/?envType=problem-list-v2&envId=prshgx6i
- Take an integer, add all the digits of that integer to get a number. If that number has more than one digit, repeat.
- I created a modular solution whereby I created a function whose purpose was to input a number and output the sum of the digits of that number. Then I ran a while loop until the num//10 == 0 as that would mean that
num
is a number with one digit.
-
https://leetcode.com/problems/score-of-a-string/submissions/1643047539/
- Given a string, calculate the difference of the ASCII values of adjacent characters
- Use
ord
to get the ASCII value of a character in Python - To get the absolute value of any number, use
abs()
instead ofmath.abs()
.
-
https://leetcode.com/problems/richest-customer-wealth/description/
- Return the max of the row wise sum of a mxn matrix
-
https://leetcode.com/problems/merge-strings-alternately/description/
- Given two strings
s1 = "abc"
ands2 = "pqr"
, merge them alternatively i.e."apbqcr"
- To solve:
- Check which word has the least length
- Run a for loop and add the characters till that least length i.e. do
merged_str = merged_str + word1[i] + word2[i]
- Then for the string that's longer (if that's even a case), add all the characters from len(shorter_str) to len(longer_word). Checkout my solution here for better context.
- Given two strings
-
https://leetcode.com/problems/fizz-buzz/description/
- Classic FizzBuzz. Need I say more?
-
https://leetcode.com/problems/convert-the-temperature/description/
- Really basic temperature conversion problem. Kind of shocked how LeetCode has this up on their website.
-
https://leetcode.com/problems/first-unique-character-in-a-string/description/
- I iterate over the string. I push each character into a list. If a character is already in the list, I set it to False in a corresponding dictionary.
- Then I iterate over the string again and return the index of the first character that is True in the dictionary.
- It's a bit slow. I'm sure there's a better way to do this.
-
https://leetcode.com/problems/sum-multiples/description/
- Variant of FizzBuzz. First check if a number is divisible by 3, 5 or 7. If it is, add it to the sum. Then check if its divisible by both (3 and 5) or (3 and 7 [i didn't do this]) or (5 and 7). If it is, add it to the sum. Then check if its divisible each of the three. If it is, add it to the sum.
- Prevents overcounting i.e. Whereby you'd count a number twice if it's divisible by both 3 and 5.
-
https://leetcode.com/problems/find-closest-person/description/
- Really simple problem. 3 people. X, Y and Z. X and Y move towards Z at the same speed. It is our job to find out who will reach Z first. This can be simply solved by taking the difference.
-
https://leetcode.com/problems/maximum-number-of-words-found-in-sentences/description/
- Loop over each sentence in the list sentences. use
.split()
to get all the words andlen()
to get the number of words and then do a simple max_wordsif
statement. Really easy problem.
- Loop over each sentence in the list sentences. use
-
[STRING] https://leetcode.com/problems/student-attendance-record-i/description/
- Loop over the string.
- First count the number of
A
s using a dictionary. If this count is ever>=2
directly returnFalse
within the loop itself. - Now we need to find a way to track if the string has 3 or more consecutive
L
. To do this, I use a variable calledlate_consec
. Whenever the loop encounters aL
this is incremented by 1. However, if the loop encounters a different letter i.e. aP
or aA
, thenlate_consec
is reset to zero. This ensures that the only waylate_consec
can be more than 3 is if the loop encounters 3 or moreL
s consecutively thereby making it impossible for the counter to be rest by any other the other if conditions. - Within the if condition for the character
L
check if the counter is>=3
or not. If it is, then returnFalse
immediately, else keep on going.
- First count the number of
- Loop over the string.
I've solved 40 problems (atleast) that's how many I've recorded in this repository. I will now transition to doing more structured practice. So I asked o3
to give me a plan and it gave me this link: https://dev.to/dfs_with_memo/leetcode-warmup-problems-13o7. I will now use this list and try to solve problems using it. I will also try to tag my problems from now on.
- [LINKED LIST] https://leetcode.com/problems/middle-of-the-linked-list/
- First get the length of the Linked List.
- Then calculate the middle index based on whether the length of the list is positive or negative.
- Then, traverse through the LL and keep a track of the number of the nodes you're visiting. The moment you hit the middle node (based on the index that was calculated earlier) save the reference of that node and break the loop.
- Return this reference. (code)
- [ARRAY] https://leetcode.com/problems/longest-continuous-increasing-subsequence/description/
- Longest Continuous Increasing Sub Sequence
- For each element of the array, I go forward as long as the previous element (prev) is lesser than the next one. If it isn't then, I append the length of the increasing sequence to a list.
- Sometimes, the list is already sorted in ascending order, so prev is never more than the next. And hence, no value is appended to my list. That's why, I use a flag variable to check if a length was ever appended to my list. If it wasn't then when I come out of the
j
or nested loop, I append the length anyways. Each time the length is reset. - This is O(n^2) and pretty slow, but it gets the job done!
- [STRINGS] https://leetcode.com/problems/find-the-difference/?envType=study-plan-v2&envId=programming-skills
- two strings,
s
andt
.t
has one extra character thats
does not have. - Goal: Print out this extra character.
- Solution: Loop through
t
. Check if that character exists ins
. If it does, remove it froms
. The first character you find that does not exists in s, is your correct answer.- Note: removal from s is important due to the case of
s='a'
andt='aa'
- Note: removal from s is important due to the case of
- two strings,
- [ARRAY] https://leetcode.com/problems/contains-duplicate/description/
- This is the first problem on Neetcode's roadmap.
- Return
True
if the Array has duplicate elements, else returnFalse
. - Initially I tried to keep a list called
app
. As I iterated through the array I checked if that particular element was already inapp
or not. If it was already present inapp
I returnedTrue
as that meant I'd seen the number before and the array did indeed contain duplicate elements. If the number wasn't present inapp
I appended it toapp
and continued with life. - However doing the above led to a
Timeout
error. So I asked GPT to guide me to the right solution using the Socratic Method and it asked me to find a more efficient data structure for theapp
list which is a Set. So I changedapp = []
toapp = set()
and found that I solved the problem! - Solution here
- NeetCode's solution: YouTube, Text
- [ARRAY] https://leetcode.com/problems/valid-anagram/
- Given two strings
s
andt
check if they are anagrams. - I created a list of all the letters in
t
. - For each character of
s
if it was present int_chars
I removed that from thet_chars
list. - At the end of the loop, if
len(t_chars)==0
I returnedTrue
, else I returnedFalse
.
- Given two strings
I know I'm flipping and flopping too much, but a friend of mine recently sent this DSAGUIDE.PDF to me and it's a really well written document that teaches the reader the fundamentals of Data Structures and Algorithms. I like the PDF and hence I'll be using it in my journey from now on.
- [ARRAY] LeetCoode 771: Jewels and Stones (https://leetcode.com/problems/jewels-and-stones/description/)
- So you have two strings,
jewels
andstones
. You have to output the number of jewels in the stones string. Each character in thejewels
string is a different type of jewel. And each character in thestones
string is a type of stone. Now some stones may be jewels while others aren't jewels. - This is a simple problem, for each character in
jewels
run a loop through the entirestones
string. If a character instones
matches the character injewels
, increment thetotal_jewels
counter by one. - Solution here.
- So you have two strings,
- https://codeforces.com/problemset/problem/4/A [Watermelon] (15 Apr 2025)
- Essentially check if a number is even and greater than 2 so that it can be split into two even numbers.
- https://codeforces.com/problemset/problem/71/A [Way Too Long Words]
- Essentially get the length of a string and if the length of the string is more than 10 then replace it with
- https://codeforces.com/problemset/problem/231/A [Team]
- Count the number of 1's in a bit string. Count if it's more than 2.
- https://codeforces.com/problemset/problem/282/A [Bit++]
- See if the string '++' is in the string and update a variable accordingly.
- In Pandas, to modify the columns
.astype('int')
or something is used in general. - In Pandas, to rename a column, you have to pass a dictionary of the
{'old_col_name': 'new_col_name'}
to the.rename()
function. - In SQL, to use the WHERE clause these two links might be helpful to refresh your memory of the Syntax (here, here)
- If you want to get the unique values from a column in SQL use the
DISTINCT
keyword. For example,SELECT DISTINCT column_name FROM table_name;
(here) - To read numbers in Bash you use
read
command. For example,read a
will read a number and store it in the variablea
. - To do arithmetic expressions in Bash using the values of variables use the
$(())
sign. For example,echo $((a+b))
will print the sum ofa
andb
. - In Pandas if you have a column say
email
in a DataFrame, say,customers
and you want to get the drop the rows where a duplicate value occurs then usecustomers.drop_duplicates(subset=['email'])
. This will drop the rows where theemail
column has duplicate values. (Nice article) sorted()
in Python returns a list whereas.sort()
just does the sort inplace on the list. So,a=sorted(list)
makes sense butb=l.sort()
will yieldNone
forb
.
Starting to maintain a table from now on.
SNo | Date | Day | Name of Problem | Platform | Description for how I solved it | What I learnt | Code |
---|---|---|---|---|---|---|---|
1 | 2025-06-18 (18th June 2025) | Wednesday | Find the Index of the First Occurrence in a String | Leetcode #28 | I slid a window across the haystack. I check character wise if the needle is equal to the haystack or not. If it is, I continue to increment a counter. The moment the counter == length of the needle that means I’ve found len(needle) number of characters in the haystack that exactly equal the characters in the haystack. To calculate the first index, I reasoned, I am starting from some index i of the haystack and I checking in front of index i by len(needle). So to get the first index, it is natural to subtract i+j (the last index where I got the total equality from len(needle)-1. | How do do this sliding window thing | Link |
2 | 2025-06-19 (19th June 2025) | Thursday | Minimum Number Game | Leetcode #2974 | Really simple problem. Until the given array is empty, let alice remove the min element from the list and then let bob remove the next min element etc. and append bob’s min element to the new list arr and then append alice’s min element to the aforementioned array arr . |
How to loop over a list and do “append” | Link |
3 | 2025-06-22 (22nd June 2025) | Sunday | Check if the Sentence Is Pangram | LeetCode #1832 | Check if a string contains all the letters of the English alphabet. How? Create a str called “alphabet_str” with all the alphabet. Loop over that string. Now for each letter of the alphabet check if the “input_str” contains that character or not. If not, immediately return False (no point searching anymore). Else, continue onwards. | How to loop and define a string (basic). Really basic stuff which I knew already but Oh well… | Link |
4 | 2025-06-23 (23rd June 2025) | Monday | Count the Digits That Divide a Number | LeetCode #2520 | Extract the digits in a number and then check if those digits actually divide the number fully. If the number is 121 the extracted digits are [1,2,1] and 1 divides 121 hence we return 2 as two of the digits in 121 divide the number 121 perfectly |
How to do basic looping stuff | Link |