<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by DataPre Pro on Medium]]></title>
        <description><![CDATA[Stories by DataPre Pro on Medium]]></description>
        <link>https://medium.com/@AvocadoandToast?source=rss-c92918b7d318------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-hn28fznnv9VUoJaSl3hsQ.png</url>
            <title>Stories by DataPre Pro on Medium</title>
            <link>https://medium.com/@AvocadoandToast?source=rss-c92918b7d318------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 23:58:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@AvocadoandToast/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Leetcode Summary 122. Best Time to Buy and Sell Stock II]]></title>
            <link>https://medium.com/@AvocadoandToast/leetcode-summary-122-best-time-to-buy-and-sell-stock-ii-26390194f6d5?source=rss-c92918b7d318------2</link>
            <guid isPermaLink="false">https://medium.com/p/26390194f6d5</guid>
            <dc:creator><![CDATA[DataPre Pro]]></dc:creator>
            <pubDate>Tue, 04 Jan 2022 00:46:04 GMT</pubDate>
            <atom:updated>2022-01-04T00:46:04.194Z</atom:updated>
            <content:encoded><![CDATA[<p>My first instinct after reading this problem is to use the two-pointer method.</p><p>Why? Because we will buy the stock first and sell it on a later day.The buying first and selling later pattern ideally needs two pointers.</p><p>When I started to coding, I was stumped by input [1, 2, 3, 4, 5]. I wanted to keep moving the right pointer if <strong>prices[l] ≤ prices[r]</strong>. However, if we use this method, we will end up having an O(n ^ 2) solution.</p><p>After second thought, I realized that since the problem requires a return value as the overall maximum profit, it doesn’t matter how often we buy and sell a share. Whether we do (2–1) + (3–2) + (4–3) + (5–4) or (5–1), we get the same result.</p><p>Below is my original code.</p><pre>class Solution(object):<br>    def maxProfit(self, prices):<br>        &quot;&quot;&quot;<br>        :type prices: List[int]<br>        :rtype: int<br>        &quot;&quot;&quot;<br>        profit = 0<br>        <br>        for l in range(len(prices)):<br>            r = l + 1<br>            if r &lt; len(prices) and prices[l] &lt;= prices[r]: <br>                profit += prices[r] - prices[l]<br>                    <br>        return profit</pre><p>Here is a more concise version from the first version.</p><pre>class Solution(object):<br>    def maxProfit(self, prices):<br>        &quot;&quot;&quot;<br>        :type prices: List[int]<br>        :rtype: int<br>        &quot;&quot;&quot;<br>        profit = 0</pre><pre>        for l in range(len(prices) - 1):<br>            if prices[l] &lt;= prices[l + 1]: <br>                profit += prices[l + 1] - prices[l]<br>                    <br>        return profit</pre><p>Time Complexity: O(n)</p><p>Space Complexity: O(1)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26390194f6d5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[9 Lessons I’ve Learned From Leaving Work At 5 pm]]></title>
            <link>https://medium.com/@AvocadoandToast/9-lessons-ive-learned-from-leaving-work-at-5-pm-2bab324e5907?source=rss-c92918b7d318------2</link>
            <guid isPermaLink="false">https://medium.com/p/2bab324e5907</guid>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[self-development]]></category>
            <category><![CDATA[self-motivation]]></category>
            <category><![CDATA[time-management]]></category>
            <dc:creator><![CDATA[DataPre Pro]]></dc:creator>
            <pubDate>Mon, 06 Jan 2020 07:20:25 GMT</pubDate>
            <atom:updated>2024-12-27T01:03:32.871Z</atom:updated>
            <content:encoded><![CDATA[<h3>9 Powerful Lessons I Learned from Leaving Work at 5 PM: Boost Productivity and Work-Life Balance</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/434/1*bJV6Lg7S9lQvs_fYjGsBYg.jpeg" /><figcaption>illustration @rachelliu_illustration</figcaption></figure><h3>The Wake-Up Call: When Overworking Takes Its Toll</h3><p>I used to be a workaholic, often staying at the office until late at night. My record? An 18-hour workday, from 10 am to 4 am. But everything changed when I fell severely ill last Christmas, forcing me to reevaluate my work-life balance.</p><h3>The 5 PM Rule: A Game-Changer for Productivity and Well-being</h3><p>This year, I implemented a new rule: leaving work at 5 pm sharp. Here are nine valuable lessons I’ve learned that can help you achieve a healthier work-life balance and boost your productivity.</p><h3>1. Accountability Is Key</h3><p>Hold yourself accountable for the rules you set. Leaving work at 5 pm means physically and mentally disconnecting from work.</p><h3>2. Communicate Your Boundaries</h3><p>Don’t be afraid to express your needs. Inform your manager and coworkers about your new schedule to set clear expectations.</p><h3>3. Master the Art of Prioritization</h3><p>With limited time, prioritizing tasks becomes crucial. Identify urgent vs. important tasks and focus on high-value work.</p><h3>4. Enhance Your Productivity Skills</h3><p>Experiment with various productivity tools and techniques to accomplish more in less time.</p><h3>5. Develop Persuasive Communication</h3><p>As you manage your time more efficiently, you’ll become more adept at explaining your decisions and proposing alternatives.</p><h3>6. Plan Your After-Work Activities</h3><p>Make the most of your newfound free time by planning meaningful activities that contribute to your personal growth.</p><h3>7. Unlock Your True Potential</h3><p>You’re capable of achieving more than you think. Push yourself within reason and watch your productivity soar.</p><h3>8. Design Your Ideal Lifestyle</h3><p>There’s no shame in pursuing the life you want. Whether it’s work-focused or balanced, make choices that align with your values.</p><h3>9. Appreciate Life’s Beauty</h3><p>Remember that life is beautiful, even during challenging times. Cherish the positive moments and keep striving for improvement.</p><h3>The Virtuous Circle of Work-Life Balance</h3><p>By implementing the 5 pm rule, I’ve entered a virtuous circle of increased productivity, better work-life balance, and improved overall well-being.</p><h3>Conclusion: Prioritize What Truly Matters</h3><p>As Marissa Mayer, former Yahoo CEO, wisely said, “You can’t have everything you want, but you can have the things that really matter to you.”Join me on this journey towards a healthier, more productive, and wiser life. It’s time to prioritize what truly matters and find your ideal work-life balance.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2bab324e5907" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Beginner’s Guide to Python Data Structure]]></title>
            <link>https://medium.com/@AvocadoandToast/a-beginners-guide-to-python-data-structure-8d79b88b1292?source=rss-c92918b7d318------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d79b88b1292</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[dictionary]]></category>
            <category><![CDATA[lists]]></category>
            <dc:creator><![CDATA[DataPre Pro]]></dc:creator>
            <pubDate>Thu, 08 Feb 2018 17:55:18 GMT</pubDate>
            <atom:updated>2018-02-08T17:55:59.810Z</atom:updated>
            <content:encoded><![CDATA[<p>What is data structure in Computer Science? A data structure is a particular way of organizing data to allow certain operations on it to be performed efficiently. I want to emphasize the difference between data type and data structure before introducing data structure categories, especially for those who learned Java first.</p><p><strong>A Data Type </strong>is a<strong> </strong>set of values (the data) associated with a set of operations defined on the data.</p><p><strong>A Data Structure </strong>is a particular way for organizing and storing data efficiently. A data structure can hold different <em>data types</em> (e.g. int, float, string).</p><p>A very intuitive example would be, if people are waiting in a checkout line for their purchases, this is a queue of people — <em>queue</em> is the data structure and people is a data type. If pigs are waiting in a line for food, this is a queue of pigs — <em>queue</em> is the data structure and pig is a data type.</p><p>Below the graph shows the classification of different data structures.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*mfrsRCyg10k1-advOYhKMg.jpeg" /><figcaption>From “Fundamentals of Python: Data Structures” by Kenneth A. Lambert</figcaption></figure><p>There are four built-in data structures in Python — <em>tuple, list, dictionary </em>and<em> set</em>. We will see when to use and how to use each of them.</p><blockquote>Tuple: A tuple is an <strong>immutable, </strong>ordered sequence of Python objects. Those objects could be different data types.</blockquote><pre>tup1 = (&#39;java&#39;, &#39;python&#39;, 2007, 2008)</pre><p>Fundamental operations:</p><pre>len(tup1)<br>max(tup1)</pre><blockquote>List: A list is an <strong>mutable, </strong>ordered sequence of Python objects. Those objects could be different data types.</blockquote><pre>list1 = [&#39;java&#39;, &#39;python&#39;, 2017, 2018]</pre><p>Fundamental operations:</p><pre>list1.insert(i, item)<br>list1.pop(i)<br>list1.append(item)<br>list1.remove(item)</pre><blockquote>Dictionary: A <em>dictionary</em> is an <strong>unordered</strong> collection of elements called <em>entries</em>. Each entry consists of a key and an associated value.</blockquote><p>A dictionary’s keys must be unique, but its values may be duplicated.</p><pre>dict1 = {&#39;apple&#39;: &#39;fruit&#39;, <br>         &#39;cabbage&#39;: &#39;vegetable&#39;, <br>         &#39;cake&#39;: &#39;dessert&#39;}</pre><p>Fundamental operations:</p><pre>dict1.pop(key)<br>dict1.keys()<br>dict1.values()<br>dict1.items()</pre><blockquote>Set: A <em>set</em> is an <strong>mutable</strong>, <strong>unordered</strong> collection of unique items(i.e. No duplicate items).</blockquote><p>Sets cannot contain<strong> </strong>mutable elements such as list, dictionary.</p><p>Fundamental operations:</p><pre>set1.add(item)<br>set1.remove(item)</pre><p><a href="https://www.ics.uci.edu/~pattis/ICS-33/lectures/complexitypython.txt">Here</a> is a good summary of time complexity comparison for operations of List, Dictionary, Set.</p><p>After familiarize yourself with basic data structures and associated operations, you may ask: “ What data structure shall I choose when solving a problem? ”</p><p>Here are two questions we could follow:</p><ol><li>To solve this problem, what operations do I use a lot?</li><li>What data structure makes these operations fast?</li></ol><p>Let’s solve a problem together to have better sense of how to choose a data structure to make an operation fast. Here is a classic problem — <a href="https://leetcode.com/problems/two-sum/description/">Two Sum</a>. I changed the example from a sorted list to unsorted list to better demonstrate difference of efficiency between List and Dictionary on the same operation.</p><blockquote><em>“Given an array of integers, return </em><strong><em>indices</em></strong><em> of the two numbers such that they add up to a specific target. You may assume that each input would have </em><strong><em>exactly</em></strong><em> one solution, and you may not use the same element twice.”</em></blockquote><p><strong>Example:</strong></p><pre>Given nums = [2, 15, 11, 7], target = 9,<br><br>Because nums[<strong>0</strong>] + nums[<strong>3</strong>] = 2 + 7 = 9,<br>return [<strong>0</strong>, <strong>3</strong>].</pre><p>The problem is to find two numbers that the sum of them would be equal to the target. You may notice the given input is an<strong> <em>array — </em></strong>Python doesn’t have a native array data structure, but it has the <strong>list</strong> which is much more general and can be used as a multidimensional array quite easily.</p><p>So for this problem, it’s very intuitive for us to pick list as the data structure to use. If we are going to use list, here is the solution:</p><p>Approach 1: brute-force search</p><p>Loop through each element v in the list and check if there is another value that equals to target-v. We will use an outer loop and an inner loop to implement this approach.</p><pre>def twoSum(self, nums, target):<br>        &quot;&quot;&quot;<br>        :type nums: List[int]<br>        :type target: int<br>        :rtype: List[int]<br>        &quot;&quot;&quot;</pre><pre>        indices = [ ]<br>        # check all the elements in the array<br>        for i in range(0, len(nums)):<br>            # check other elements in the array<br>            for j in range(i+1, len(nums)):<br>                if (nums[i] == target - nums[j]):<br>                    indices.append(i)<br>                    indices.append(j)<br>        return indices</pre><ul><li>Time complexity : O(n²). For each element, we try to find its complement by looping through the rest of list which takes O(n) * <em>O</em>(<em>n</em>) time. Therefore, the time complexity is O(n²).</li><li>Space complexity : O(1). We do not use extra space except the given array.</li></ul><p>The O(n²) time complexity is pretty inefficient. What is a better approach? Let’s follow these two questions:</p><blockquote><em>To solve this problem, what operations do I use a lot?</em></blockquote><p><strong>Lookups</strong>. We need repeated lookups to find the value and index of each element and that of its complement in the given array.</p><blockquote>What data structure makes <strong>lookups</strong> fast?</blockquote><p><strong>Dictionary</strong>. We need to return indices of a number and its complement that satisfy the problem’s statement. Each element has a “<strong>element : index</strong>”<strong> </strong>mapping relationship. What is the best way to maintain a mapping of each element in the array to its index? A dictionary.</p><p>Approach 2: Use a dictionary.</p><ol><li>Create a dictionary.</li><li>Loop through the elements of nums, getting i as index, and v as value. Each time get one pair of value:index.</li><li>Check if target-v is a key in the dictionary we created. If this is ever true, return these two numbers’ indices as [dict[target-v], i] right away. Otherwise, put this pair of value:index in the dictionary and start the next iteration.</li></ol><pre>def twoSum(self, nums, target):<br>        &quot;&quot;&quot;<br>        :type nums: List[int]<br>        :type target: int<br>        :rtype: List[int]<br>        &quot;&quot;&quot;</pre><pre>        dict = {}<br>        for i in xrange(len(nums)):<br>            v = nums[i]<br>            if target-v in dict:<br>                return [dict[target-v], i]<br>            dict[v] = i</pre><ul><li>Time complexity : O(n). We traverse the list containing n elements only once. Each look up in the table costs only O(1) time.</li><li>Space complexity : O(n). We created a dictionary which takes extra space required depends on the number of items stored in the dictionary — It stores at most n elements.</li></ul><p>From this problem, we could see the time complexity and space complexity would change a lot if we choose a different data structure. If solving a problem needs repeated lookups, then we’d choose dictionary. If we need sort/care about order, we will choose list.</p><p>Other important data structures such as Tree, Queue, Stack, I will write a serial of summaries to demonstrate use cases of those data structures. For now, <a href="https://medium.freecodecamp.org/all-you-need-to-know-about-tree-data-structures-bceacb85490c">here</a> is a very good reading material for Tree.</p><p>References:</p><ol><li><a href="https://leetcode.com/problems/two-sum/solution/">Leetcode Two Sum Solution</a></li><li>“Fundamentals of Python: Data Structures” by Kenneth A. Lambert</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d79b88b1292" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Beginner’s Guide to Big O notation]]></title>
            <link>https://medium.com/@AvocadoandToast/a-beginners-guide-to-big-o-notation-793d654973d?source=rss-c92918b7d318------2</link>
            <guid isPermaLink="false">https://medium.com/p/793d654973d</guid>
            <category><![CDATA[big-o-notation]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[DataPre Pro]]></dc:creator>
            <pubDate>Tue, 06 Feb 2018 22:11:00 GMT</pubDate>
            <atom:updated>2018-02-08T19:19:11.981Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_nsMVEEkIr1CH8aHjTNbzA.jpeg" /></figure><p>What is a Big O notation? Big O notation(“O” stands for “order”) is the language we use in Computer Science to describe the performance of an algorithm.</p><p>How to quantify the performance of an algorithm? We could quantify it by(i)time cost and (ii) space cost. For time cost, Big O notation describes how much runtime an algorithm takes to run as the size <strong>n </strong>of input data set increases. In other words, Big O notation shows how quickly the runtime of executing an algorithm grows in “worst case”. For space cost, Big O notation describes how large of additional space(relative to the size <strong>n</strong> of input data set) an algorithm needs.</p><p>Why do we need “Big O” notation? In order to choose the suitable algorithm for the problem we want to solve. For example, if we want to sort a list, and here are different algorithms to accomplish this task(e.g. Merge Sort, Quick Sort, Bubble Sort). In order to compare the efficiency of different algorithms, we use “Big O” notation. Sometimes we will choose an algorithm that occupies less space but more time if additional space is very expensive to the company.</p><p>Here are some examples we could look at for each time complexity. All the examples are shown in Python.</p><blockquote>Time Complexity: O(1)</blockquote><blockquote>Name: Constant</blockquote><blockquote>Example operations: append, get item, set item.</blockquote><pre># Append an element to a list<br>myList = [ ]<br>myList.append(666)<br>print myList</pre><pre><em># return [666]</em></pre><blockquote>Time Complexity: O(log n)</blockquote><blockquote>Name: Logarithmic</blockquote><blockquote>Example operations: Finding an element in a sorted array.</blockquote><pre># Find target 22 (i.e. return its index)in a sorted list<br># Here we use Binary Search algorithm because its time complexity is O(log n)<br>def binarySearch(sortedList, target):<br> left = 0<br> right = len(sortedList) - 1<br> while (left &lt;= right):<br>  mid = (left + right)/2<br>  if (sortedList(mid) == target):<br>   return mid<br>  elif(sortedList(mid) &lt; target):<br>   left = mid + 1<br>  else:<br>   right = mid - 1<br># If target is not in the list, return -1<br> return -1</pre><pre>binarySearch([1,3,9,22],22)<br><em># return 3</em></pre><blockquote>Time Complexity: O(n)</blockquote><blockquote>Name: Linear</blockquote><blockquote>Example operations: copy, insert, delete, iteration.</blockquote><p>Here is another example of the same operation — Finding an item in a sorted list. This algorithm is intuitively less efficient than binary search.</p><pre># Find target 22 (i.e. return its index)in a sorted list<br>def linearSearch(sortedList, target):<br>  for i in range(len(sortedList)):<br>    if (sortedList[i] == target):<br>    return i<br># If target is not in the list, return -1<br>  return -1</pre><pre>linearSearch([1,3,9,22],22)<br><em># return 3</em></pre><blockquote>Time Complexity: O(nLog n)</blockquote><blockquote>Name: Linear-Logarithmic</blockquote><blockquote>Example operations: Sort a list, for example, merge sort.</blockquote><pre># Merge sort<br>def mergeSort(alist):<br>    if len(alist)&gt;1:<br>        mid = len(alist)//2<br>        leftHalf = alist[:mid]<br>        rightHalf = alist[mid:]</pre><pre>        mergeSort(leftHalf)<br>        mergeSort(rightHalf)</pre><pre>        i=0<br>        j=0<br>        k=0<br>        while i &lt; len(leftHalf) and j &lt; len(rightHalf):<br>            if leftHalf[i] &lt; rightHalf[j]:<br>                alist[k]= leftHalf[i]<br>                i=i+1<br>            else:<br>                alist[k]=rightHalf[j]<br>                j=j+1<br>            k=k+1</pre><pre>        while i &lt; len(leftHalf):<br>            alist[k]=leftHalf[i]<br>            i=i+1<br>            k=k+1</pre><pre>        while j &lt; len(rightHalf):<br>            alist[k]=rightHalf[j]<br>            j=j+1<br>            k=k+1</pre><pre>alist = [11,22,55,44,77,66,44,33,88]<br>mergeSort(alist)<br>print(alist)</pre><blockquote>Time Complexity: O(n²)</blockquote><blockquote>Name: Quadratic</blockquote><blockquote>Example operations: Find the shortest path between two nodes in a graph. Nested loops.</blockquote><pre># Nested loops - pseudo code<br>for (list in list_groups):<br>    for (word in work_list):<br>        if (word == target_word):<br>            return 1<br>return -1</pre><blockquote>Time Complexity: O(n³)</blockquote><blockquote>Name: Cubic</blockquote><blockquote>Example operations: Matrix multiplication.</blockquote><pre># 3 loops - pseudo code<br>for (i in range1):<br>    for (j in range2):<br>         for (k in range 3):<br>           if (aList[k] == target_word):<br>               return 1<br>     return -1<br>return -1</pre><blockquote>Time Complexity: O(2^n)</blockquote><blockquote>Name: Exponential</blockquote><blockquote>Example operations: ‘Towers of Hanoi’ problem, backtracking.</blockquote><pre># Recursive calculation of Fibonacci numbers<br>def fibonacci(num):<br>    if (num &lt;= 1):<br>       return num<br>    return fibonacci(number - 2) + fibonacci(number - 1)</pre><p><a href="http://sahandsaba.com/five-ways-to-calculate-fibonacci-numbers-with-python-code.html">Here</a> is more information about Fibonacci numbers.</p><p>Reference: “Python Data Structures and Algorithms” by Benjamin Baka</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=793d654973d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>