├── August Leetcode Challenge ├── D1. DetectCapital.py ├── D2. DesignHashSet.py ├── D3. ValidPalindrom.py ├── D4. PowerOfFour.py ├── D5. AddandSearchWord.py ├── D6. FindAllDuplicatespy.py └── D7. VerticalOrderTraversalBT.py ├── November Leetocde Challenge └── D01 Number of Recent Calls │ ├── README.md │ └── d1_solution.py ├── Problem code submissions ├── .idea │ ├── vcs.xml │ └── workspace.xml ├── 1189. Maximum Number of Balloons.py ├── 1207. Unique Number of Occurrences.py ├── 1295. Find Numbers with Even Number of Digits.py ├── 1304. Find N Unique Integers Sum up to Zero.py ├── 136. Single Number.py ├── 144. BinaryTreePreorderTraversal.py ├── 1448. Count Good Nodes in Binary Tree.py ├── 145. BinaryTreePostorderTraversal.py ├── 1450. Number of Students Doing Homework at a Given Time.py ├── 1550. Three Consecutive Odds.py ├── 1619. Mean of Array After Removing Some Elements.py ├── 1636. Sort Array by Increasing Frequency.py ├── 1721. Swapping Nodes in a Linked List.py ├── 1748. Sum of Unique Elements.py ├── 1816. Truncate Sentence.py ├── 1822. Sign of the Product of an Array.py ├── 1869. Longer Contiguous Segments of Ones than Zeros.py ├── 2027. Minimum Moves to Convert String.py ├── 206. Reverse LinkedList.py ├── 217. Contains Duplicate.py ├── 220. Contains Duplicate III.py ├── 242. Valid Anagram.py ├── 344. Reverse String.py ├── 387. First Unique Character in a String.py ├── 453. Minimum Moves to Equal Array Elements.py ├── 459. Repeated Substring Pattern.py ├── 500. Keyboard Row.py ├── 5734. Check if the Sentence Is Pangram.py ├── 5735. Maximum Ice Cream Bars.py ├── 5736. Single-Threaded CPU.py ├── 5737. Find XOR Sum of All Pairs Bitwise AND.py ├── 575. Distribute Candies.py ├── 75. Sort Colors.py ├── 763. Partition Labels.py ├── 771. Jewels and Stones.py ├── 884. Uncommon Words from Two Sentences.py ├── 94. BinaryTreeInorderTraversal.py └── 949. Largest Time for Given Digits.py ├── README.md ├── September Leetcode Challenge ├── D01 LargestTimeforGivenDigits │ ├── README.md │ ├── cover.jpg │ └── d1_solution.py ├── D02 ContainsDuplicateIII │ ├── README.md │ ├── cover.jpg │ └── d2_solution.py ├── D03 RepeatedSubstringPattern │ ├── README.md │ ├── cover.jpg │ └── d3_solution.py ├── D04 Partition Labels │ ├── README.md │ ├── cover.jpg │ └── d4_solution.py ├── D05 All Elements in Two Binary Search Trees │ ├── README.md │ ├── cover.jpg │ └── d5_solution.py ├── D06 Image Overlap │ ├── README.md │ ├── cover.jpg │ └── d6_solution.py ├── D07 Word Pattern │ ├── README.md │ ├── cover.jpg │ └── d7_solution.py ├── D08 Sum of Root to Leaf Binary Numbers │ ├── README.md │ ├── cover.jpg │ ├── d8_solution.py │ └── example_1.png ├── D09 Compare Version numbers │ ├── README.md │ ├── cover.jpg │ └── d9_solution.py ├── D10 Bulls and Cows │ ├── README.md │ ├── cover.jpg │ └── d10_solution.py ├── D11 Maximum Product Subarray │ ├── README.md │ ├── cover.jpg │ └── d11_solution.py ├── D12 Combination Sum III │ ├── README.md │ ├── cover.jpg │ └── d12_solution.py ├── D13 Insert Interval │ ├── README.md │ ├── cover.jpg │ └── d13_solution.py ├── D14 House Robbers │ ├── README.md │ ├── cover.jpg │ └── d14_solution.py ├── D15 Length of Last Word │ ├── README.md │ ├── cover.jpg │ └── d15_solution.py ├── D16 Maximum XOR of Two Numbers in an Array │ ├── README.md │ ├── cover.jpg │ └── d16_solution.py ├── D17 Robot Bounded In Circle │ ├── README.md │ ├── cover.jpg │ └── d17_solution.py ├── D18 Best Time to Buy and Sell Stock │ ├── README.md │ ├── cover.jpg │ └── d18_solution.py ├── D19 Sequential Digits │ ├── README.md │ ├── cover.jpg │ └── d19_solution.py ├── D20 Unique Paths III │ ├── README.md │ ├── cover.jpg │ └── d20_solution.py ├── D21 Car Pooling │ ├── README.md │ ├── cover.jpg │ └── d21_solution.py ├── D22 Majority Element II │ ├── README.md │ ├── cover.jpg │ └── d22_solution.py ├── D23 Gas Station │ ├── README.md │ ├── cover.jpg │ └── d23_solution.py ├── D24 Find the Difference │ ├── README.md │ ├── cover.jpg │ └── d24_solution.py ├── D25 Largest Number │ ├── README.md │ ├── cover.jpg │ └── d25_solution.py ├── D26 Teemo Attacking │ ├── README.md │ ├── cover.jpg │ └── d26_solution.py ├── D27 Evaluate Division │ ├── README.md │ ├── cover.jpg │ └── d27_solution.py ├── D28 Subarray Product Less Than K │ ├── README.md │ ├── cover.jpg │ └── d28_solution.py ├── D29 Word Break │ ├── README.md │ ├── cover.jpg │ └── d29_solution.py └── D30 First Missing Positive │ ├── README.md │ ├── cover.jpg │ └── d30_solution.py └── Weekly contest ├── Weekly Contest 255 └── 5850. Find Greatest Common Divisor of Array.py ├── Weekly contest 237 ├── 5734. Check if the Sentence Is Pangram.py ├── 5735. Maximum Ice Cream Bars.py ├── 5736. Single-Threaded CPU.py └── 5737. Find XOR Sum of All Pairs Bitwise AND.py ├── Weekly contest 239 └── 5746. Minimum Distance to the Target Element.py ├── Weekly contest 242 └── 1869. Longer Contiguous Segments of Ones than Zeros.py ├── weekly contest 228 ├── 5676. Minimum Changes To Make Alternating Binary String.py └── 5677. Count Number of Homogenous Substrings.py └── weekly contest 236 └── 1822. Sign of the Product of an Array.py /August Leetcode Challenge/D1. DetectCapital.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def detectCapitalUse(self, word: str) -> bool: 3 | if len(word) <= 1: 4 | return True 5 | if word.isupper() or word.islower(): 6 | return True 7 | elif word[0].isupper() and word[1:].islower(): 8 | return True 9 | return False -------------------------------------------------------------------------------- /August Leetcode Challenge/D2. DesignHashSet.py: -------------------------------------------------------------------------------- 1 | class MyHashSet: 2 | 3 | def __init__(self): 4 | self.s=set() 5 | 6 | def add(self, key: int) -> None: 7 | self.s.add(key) 8 | 9 | def remove(self, key: int) -> None: 10 | self.s.discard(key) 11 | 12 | def contains(self, key: int) -> bool: 13 | return key in self.s -------------------------------------------------------------------------------- /August Leetcode Challenge/D3. ValidPalindrom.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPalindrome(self, s: str) -> bool: 3 | s2 = "" 4 | for i in range(len(s)): 5 | if s[i].isalnum(): 6 | s2 += s[i] 7 | return s2.lower() == s2[::-1].lower() -------------------------------------------------------------------------------- /August Leetcode Challenge/D4. PowerOfFour.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPowerOfFour(self, num: int) -> bool: 3 | #with loop only 4 | if (num == 4 or num == 1): 5 | return True 6 | 7 | if (num < 4 or num % 4 != 0): 8 | return False 9 | #looping 10 | temp = num 11 | while (temp > 1): 12 | if (temp % 4 != 0): 13 | return False 14 | temp = temp / 4 15 | return temp == 1 -------------------------------------------------------------------------------- /August Leetcode Challenge/D5. AddandSearchWord.py: -------------------------------------------------------------------------------- 1 | class WordDictionary: 2 | 3 | def __init__(self): 4 | self.words = {} 5 | 6 | 7 | def addWord(self, word: str) -> None: 8 | length = len(word) 9 | if length not in self.words: 10 | self.words[length] = [word] 11 | else: 12 | self.words[length].append(word) 13 | 14 | 15 | def search(self, word: str) -> bool: 16 | new_word_length = len(word) 17 | if new_word_length not in self.words: 18 | return False 19 | 20 | #If we are here then that means we have atleast one word of the same length as our search word 21 | all_words = self.words[len(word)] 22 | for i in range(len(all_words)): 23 | current_word = all_words[i] 24 | is_present = True 25 | for j in range(len(current_word)): 26 | if current_word[j] == word[j] or word[j] == ".": 27 | continue 28 | else: 29 | is_present = False 30 | break 31 | if is_present: 32 | return True 33 | return False 34 | 35 | 36 | 37 | # Your WordDictionary object will be instantiated and called as such: 38 | # obj = WordDictionary() 39 | # obj.addWord(word) 40 | # param_2 = obj.search(word) -------------------------------------------------------------------------------- /August Leetcode Challenge/D6. FindAllDuplicatespy.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findDuplicates(self, nums: List[int]) -> List[int]: 3 | d1=dict() 4 | result=[] 5 | for key in nums: 6 | #elements either appear once or twice 7 | #if they have appeared once update result else append in the dict with count as one. 8 | if key in d1: 9 | result.append(key) 10 | else: 11 | d1[key] = 1 12 | return(result) 13 | -------------------------------------------------------------------------------- /August Leetcode Challenge/D7. VerticalOrderTraversalBT.py: -------------------------------------------------------------------------------- 1 | # Definition for a binary tree node. 2 | # class TreeNode: 3 | # def __init__(self, val=0, left=None, right=None): 4 | # self.val = val 5 | # self.left = left 6 | # self.right = right 7 | class Solution: 8 | def verticalTraversal(self, root: TreeNode) -> List[List[int]]: 9 | order = defaultdict(list) 10 | def traverse(root,level,h): 11 | if root: 12 | order[level].append((h,root.val)) 13 | traverse(root.left,level-1,h+1) 14 | traverse(root.right,level+1,h+1) 15 | return 16 | return 17 | traverse(root,0,1) 18 | result = [] 19 | order = sorted(order.items(), key = lambda i:i) 20 | 21 | for k, v in dict(order).items(): 22 | v_sorted = sorted(v) 23 | temp = [] 24 | for _, n in v_sorted: 25 | temp.append(n) 26 | result.append(temp) 27 | 28 | return result 29 | -------------------------------------------------------------------------------- /November Leetocde Challenge/D01 Number of Recent Calls/README.md: -------------------------------------------------------------------------------- 1 | Number of Recent Calls 2 | ========================== 3 | You can find a complete step by step explanation walkthrough at my september Leetcode challenge [Youtube Playlist](https://www.youtube.com/playlist?list=PLjaO05BrsbIP4_rYhYjB95q-IpxoIXmlm) 4 | 5 | Problem Statement: 6 | ========================== 7 | You have a RecentCounter class which counts the number of recent requests within a certain time frame. 8 | 9 | Implement the RecentCounter class: 10 | 11 | RecentCounter() Initializes the counter with zero recent requests. 12 | int ping(int t) Adds a new request at time t, where t represents some time in milliseconds, and returns the number of requests that has happened in the past 3000 milliseconds (including the new request). Specifically, return the number of requests that have happened in the inclusive range [t - 3000, t]. 13 | It is guaranteed that every call to ping uses a strictly larger value of t than the previous call. 14 | 15 | --- 16 | Example 1: 17 | ========================== 18 | ``` 19 | Input 20 | ["RecentCounter", "ping", "ping", "ping", "ping"] 21 | [[], [1], [100], [3001], [3002]] 22 | Output 23 | [null, 1, 2, 3, 3] 24 | 25 | Explanation 26 | RecentCounter recentCounter = new RecentCounter(); 27 | recentCounter.ping(1); // requests = [1], range is [-2999,1], return 1 28 | recentCounter.ping(100); // requests = [1, 100], range is [-2900,100], return 2 29 | recentCounter.ping(3001); // requests = [1, 100, 3001], range is [1,3001], return 3 30 | recentCounter.ping(3002); // requests = [1, 100, 3001, 3002], range is [2,3002], return 3 31 | ``` 32 | 33 | Constraints: 34 | ========================== 35 | ``` 36 | 1 <= t <= 109 37 | Each test case will call ping with strictly increasing values of t. 38 | At most 104 calls will be made to ping. 39 | ``` -------------------------------------------------------------------------------- /November Leetocde Challenge/D01 Number of Recent Calls/d1_solution.py: -------------------------------------------------------------------------------- 1 | class RecentCounter: 2 | ''' 3 | Problem Name: Number of Recent Calls 4 | Author: Ayushi Rawat 5 | Date: 01-10-2020 6 | ''' 7 | 8 | def __init__(self): 9 | self.slide_window = deque() 10 | 11 | def ping(self, t: int) -> int: 12 | self.slide_window.append(t) 13 | 14 | while self.slide_window[0] < t - 3000: 15 | self.slide_window.popleft() 16 | 17 | return len(self.slide_window) 18 | -------------------------------------------------------------------------------- /Problem code submissions/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Problem code submissions/.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |