Today was the first day of the schedule I outlined in my previous post. It didn’t go exactly to plan, but I made progress on both of the blocks I had set aside for the day.
Setbacks
Procrastination was an issue from the start of the day. I pushed my original start time back by an hour and a half, which had a knock-on effect: my second block ended up overlapping with other plans, so it got pushed to the end of the day.
Now that the habit is underway, I’m hoping it’ll be easier to stick to the schedule more strictly and avoid repeating the same mistake.
Basic Python Exercises
I’m using Exercism to work through the fundamentals. I installed their CLI tool via Homebrew, started the Python track, and completed the concepts and exercises for basics, numbers, and bools.
Data Structures & Algorithms
I started working through the NeetCode 150 roadmap, beginning with the Arrays section.
Contains Duplicate
Contains Duplicate gives you a list of integers and asks whether any value appears more than once. It should return True if there’s a duplicate and False if every element is distinct.
This one was a quick solve. I used a set to track the numbers I’d already seen while iterating over the list, returning True as soon as I hit a number that was already in the set. If the loop finishes without an early return, the answer is False.
Valid Anagram
Valid Anagram takes two strings and asks whether one is an anagram of the other, meaning both contain exactly the same characters with the same counts, just possibly in a different order.
I remembered solving this one in the past, so it went quickly as well. First, I check that both words are the same length and return False early if they’re not. Then I wrote a helper function that turns a string into a hash map, with each letter as a key and the number of times it appears as the value. Calling it on both words and comparing the results gives the answer.
Two Sum
Two Sum gives you a list of integers and a target value, and asks for the indices of the two numbers that add up to the target. Each input is guaranteed to have exactly one solution, and the same element can’t be used twice.
My first attempt used a two-pointer approach, which passed the initial test cases but timed out on others once I submitted. After refreshing my memory with a YouTube video, I pivoted to using a dict to store the numbers I’d already iterated over. For each new number, I check whether its complement (the target minus the current number) is already in the dict, which finds the match in a single pass.
Group Anagrams
Group Anagrams takes a list of strings and asks you to group together the ones that are anagrams of each other, returning the groups as a list of lists in any order.
The problem itself wasn’t too challenging, but it exposed a lot of gaps in my basic Python syntax. I stumbled over appending to, iterating over, and accessing values in several data structures, including tuples, lists, and defaultdict.
Takeaways
Basic Python syntax is starting to come back to me, but I still needed several Google searches to get through some of today’s exercises. That’s exactly the kind of friction I’m hoping to eliminate over the coming weeks.
