Longest Substring Without Repeating Characters – Python 3 (Week 12 -09)

Solution 1 HashMap Time complexity : O ( n ) . Index j will iterate n times. Space complexity O(min(m,n)). We need O(k) space for the sliding window, where k is the size of the Set. The size of the Set is upper bounded by the size of the string n and the size of …

#Group Anagrams – Python 3 (Week 12 – 06)

Solution 1 class Solution: “”” @param strs: the given array of strings @return: The anagrams which have been divided into groups “”” def groupAnagrams(self, strs): # write your code here dic = {} for item in sorted(strs): sortedItem = ”.join(sorted(item)) dic[sortedItem] = dic.get(sortedItem, []) + [item] return dic.values() Time Complexity: O ( N K log …

Design a site like this with WordPress.com
Get started