RMRohan Morarinrohanmorar.hashnode.dev·Apr 30, 2023 · 2 min read05-1 : Top K Frequent ElementsOverview I walk you through how to solve Leetcode problem 347. Top K Frequent Elements. Approach 1: Count HashMap def topKFrequent(nums, k): count = {} res = [] for n in nums: count[n] = count.get(n, 0) + 1 for _ in range(k): ...00
RMRohan Morarinrohanmorar.hashnode.dev·Apr 28, 2023 · 2 min read04-1 : Group AnagramsOverview I walk you through how to solve Leetcode problem 49. Group Anagrams. There are a couple of approaches to solving this problem. I will highlight both approaches as well as the time and space complexity trade-offs between each approach. Approa...00
RMRohan Morarinrohanmorar.hashnode.dev·Apr 28, 2023 · 4 min readBinary Search Tree (BST) OverviewBackground Linked List vs. Array - search() Linked lists have a slight downside when it comes to finding an item. If the item we're trying to find is located towards the end, then we'd have to traverse nearly all nodes until it's found. The result is...00
RMRohan Morarinrohanmorar.hashnode.dev·Apr 27, 2023 · 1 min read03-2 : Count characters in your stringThis is a CodeWars problem that requires returning a HashMap of the count of characters within a string. Approach 1: HashMap def count(s): letterCount = {} for c in s: letterCount[c] = 1 + letterCount.get(c, 0) return letterCount ...00
RMRohan Morarinrohanmorar.hashnode.dev·Apr 27, 2023 · 1 min read03-1 : Two SumI walk you through how to solve Leetcode problem 1. Two Sum. I highlight a couple of approaches to solving it. As usual, there are various trade-offs between time and space complexity respective to each approach. Approach 1: Brute Force def twoSum(nu...00