Posts

Showing posts from September, 2026

Learn to THINK. Learn to CODE — Day 03: Two Pointers

So far we solved problems where we scanned a list of items, and used simple tools to remember what we had seen. But think about it. If a list has 100 items, do you want to go through it one by one? Until now we used one pointer to move through the list. To read n items, it takes n steps. What if you use two pointers instead? You can often read the list faster and make better decisions along the way. That is the technique we are learning today. Two pointers. Here is a simple way to feel the idea. Imagine you have one task, and you split it between 2 engineers. One engineer is doing very well. The other is not. Which side do you push a little more? You push the side that is limiting the progress. Correct. Two pointers works the same way. You start with two pointers, left and right. Whichever side is limiting the result, you move that side. Keep our rule in mind the whole time: Understand the problem clearly. Break it into small parts. Work thr...

Learn to Think. Learn to Code : 02

 We learnt so far how to read a list of items. Next steps, we are going to learn some tools that we can use to store something and retrieve it on demand. When it comes to finishing any job faster, there are only 2 things -  Do less units of work Whatever work you are doing, do it efficiently These 2 tools will help you do a work efficiently. TOOL 1: HashMap To create, mmap = {} or {0:1} To add a value, mmap[1] = 5 To check if something exist, if value in mmap You can google to see the different options with hashmap. 169. Majority Element     def majorityElement(self, nums: List[int]) -> int:         maj = len(nums)/2         # I need some place to store by key and value how many times an item occured.         # Key is the item and value is its count         ocMap = {}         for num in nums:             # I am checking if the number is...

Learn to Think. Learn to Code : 01

This series is about learning and training your mind to think. I use small, everyday problems as a training ground, because thinking is a skill, and like any skill, it is built one habit at a time. At the end of each step I add one classic practice problem, these are simple, well-known problems anyone can use to strengthen the habit. This week’s theme: Reading a stream of information and making the best decision as you go. Article Summary You will train your mind to read a list of information, remember what you already read, how to build on top of what you already know rather than starting all over every time, how to keep a reference and then update it based on future events, you learn to set benchmark & compare against and finally use everything you learnt to solve the problem Step 1: The Combine The scenario: You have two amounts in your hand. Someone asks you for one final number. That is the whole task. It sounds almost too simple to matter, but this is the very first unit of c...