All Posts

  • December 2023 – Recap

    Unfortunately on December I got Influenza A which lasted for 2 weeks + I had finals 😦 so I had a pause since 12th. After that I felt the need to learn C++ more so I have been studying C++ and some concepts from C… Read more

  • Category:

    Difficulty: EasyTopics: Math, String For two strings s and t, we say “t divides s” if and only if s = t + … + t (i.e., t is concatenated with itself one or more times). Given two strings str1 and str2, return the largest string x such that x divides both str1 and str2. I initially solved this like this: string gcdOfStrings(string str1, string… Read more

  • Boyer–Moore majority vote algorithm

    Links: Original Paper published in 1991 (pg. 105-117) I was solving 169. Majority Element and was struggling to find a one passalgorithm with O(1) space (these are called streaming algorithms). The best I could figure out was in O(n^2) time + O(1) space or O(nlogn) time… Read more

  • Category:

    Implementation may use dynamic array and an index pointing to the head of the queue. should support enqueue (appends a new element), dequeue (removes the first element). class MyQueue {    private:        vector<int> data;              int p_start;             … Read more

  • Hoare’s selecting algorithm is a textbook algorithm used to solve “find kth something”: kth smallest, kth largest, kth most frequent, kth less frequent, etc. Time Complexity: Average O(n), Worst case O(n^2) See 347. Top K Frequent Elements. Below, we solve this question with Hoare’s Quickselect. Hoare’s Quickselect In a hashmap of <element, frequency>, select a… Read more

  • Category:

    Difficulty: mediumTopics: Hash Table, String, Sliding Window Given a string s, find the length of the longest substring without repeating characters. Example 1:Input: s = “abcabcbb”Output: 3Explanation: The answer is “abc”, with the length of 3. Example 2:Input: s = “bbbbb”Output: 1Explanation: The answer is… Read more

  • November 2023 – Recap

    Hello. I’m writing this at 5:00 AM. This month was somewhat busy, but since November 11, when I decided to commit at least 1 hour to PS every day, I have been keeping it. No matter if I have a midterm tomorrow, an internship application… Read more