https://leetcode.com/problems/alien-dictionary/ Alien Dictionary Total Accepted: 1390 Total Submissions: 8315 Difficulty: Hard There is a new alien language which uses the latin alphabet. However, the order among letters are unknown to you. You receive a list of words from the dictionary, where words are sorted lexicographically by the rules of this new language. Derive the order …
Category Archives: leetcode
Leetcode 146: LRU cache
https://leetcode.com/problems/lru-cache/ LRU Cache Total Accepted: 50542 Total Submissions: 329169 Difficulty: Hard Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set. get(key) – Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.set(key, value) …
Leetcode 271: Encode and Decode Strings
https://leetcode.com/problems/encode-and-decode-strings/ Encode and Decode Strings Total Accepted: 1272 Total Submissions: 4999 Difficulty: Medium Design an algorithm to encode a list of strings to a string. The encoded string is then sent over the network and is decoded back to the original list of strings. Machine 1 (sender) has the function: string encode(vector<string> strs) { // …
Leetcode 15: 3Sum
https://leetcode.com/problems/3sum/ 3Sum Total Accepted: 78227 Total Submissions: 457872 Difficulty: Medium Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: Elements in a triplet (a,b,c) must be …
Leetcode 1: Two sums
https://leetcode.com/problems/two-sum/ Two Sum Total Accepted: 141545 Total Submissions: 770154 Difficulty: Medium Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please …
Leetcode 33: Search in Rotated Sorted Array
https://leetcode.com/problems/search-in-rotated-sorted-array/ Search in Rotated Sorted Array Total Accepted: 72911 Total Submissions: 252621 Difficulty: Hard Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). You are given a target value to search. If found in …
Continue reading “Leetcode 33: Search in Rotated Sorted Array”
Leetcode 272: Closest Binary Search Tree Value II
https://leetcode.com/problems/closest-binary-search-tree-value-ii/ Closest Binary Search Tree Value II Total Accepted: 1212 Total Submissions: 4499 Difficulty: Hard Given a non-empty binary search tree and a target value, find k values in the BST that are closest to the target. Note: Given target value is a floating point. You may assume k is always valid, that is: k …
Continue reading “Leetcode 272: Closest Binary Search Tree Value II”
Leetcode 10: Regular Expression Matching
https://leetcode.com/problems/regular-expression-matching/ Regular Expression Matching Total Accepted: 57005 Total Submissions: 274700 Difficulty: Hard Implement regular expression matching with support for '.' and '*'. ‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). The function prototype should be: bool isMatch(const char *s, …
Leetcode 270: Closest Binary Search Tree Value
https://leetcode.com/problems/closest-binary-search-tree-value/ Closest Binary Search Tree Value Total Accepted: 2218 Total Submissions: 7604 Difficulty: Easy Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target. Note: Given target value is a floating point. You are guaranteed to have only one unique value in the …
Continue reading “Leetcode 270: Closest Binary Search Tree Value”
Leetcode 275 : H-Index II
https://leetcode.com/discuss/56122/standard-binary-search H-Index II Total Accepted: 7373 Total Submissions: 23549 Difficulty: Medium Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm? Code 1: class Solution(object): def hIndex(self, citations): “”” :type citations: List[int] :rtype: int “”” if citations is None or len(citations) == 0: return 0 for …