This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Given the root of a binary search tree, rearrange the tree in in-order so that the leftmost node in the tree is now | |
| the root of the tree, and every node has no left child and only one right child. | |
| Example 1: | |
| Input: root = [5,3,6,2,4,null,8,1,null,null,null,7,9] | |
| Output: [1,null,2,null,3,null,4,null,5,null,6,null,7,null,8,null,9] | |
| Example 2: | |
| Input: root = [5,1,7] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Linked List Random Node | |
| Given a singly linked list, return a random node's value from the linked list. | |
| Each node must have the same probability of being chosen. | |
| Follow up: | |
| What if the linked list is extremely large and its length is unknown to you? | |
| Could you solve this efficiently without using extra space? | |
| Example: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Given a list of words and two words word1 and word2, return the shortest distance between these two words in the list. | |
| Example: | |
| Assume that words = ["practice", "makes", "perfect", "coding", "makes"]. | |
| Input: word1 = “coding”, word2 = “practice” | |
| Output: 3 | |
| Input: word1 = "makes", word2 = "coding" | |
| Output: 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Given a linked list, return the node where the cycle begins. If there is no cycle, return null. | |
| There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail's next pointer is connected to. Note that pos is not passed as a parameter. | |
| Notice that you should not modify the linked list. | |
| Follow up: | |
| Can you solve it using O(1) (i.e. constant) memory? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Given a binary tree, find its minimum depth. | |
| The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. | |
| Note: A leaf is a node with no children. | |
| Input: root = [3,9,20,null,null,15,7] | |
| Output: 2 | |
| Example 2: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Design a data structure that accepts a stream of integers and checks if it has a pair of integers that sum up to a particular value. | |
| Implement the TwoSum class: | |
| TwoSum() Initializes the TwoSum object, with an empty array initially. | |
| void add(int number) Adds number to the data structure. | |
| boolean find(int value) Returns true if there exists any pair of numbers whose sum is equal to value, otherwise, it returns false. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Given a list of intervals, remove all intervals that are covered by another | |
| interval in the list. | |
| Interval [a,b) is covered by interval [c,d) if and only if c <= a and b <= d. | |
| After doing so, return the number of remaining intervals. | |
| Example 1: | |
| Input: intervals = [[1,4],[3,6],[2,8]] | |
| Output: 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Given an array of integers nums and an integer k, return the number of | |
| unique k-diff pairs in the array. | |
| A k-diff pair is an integer pair (nums[i], nums[j]), where the following are | |
| true: | |
| 0 <= i, j < nums.length | |
| i != j | |
| a <= b |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. | |
| You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next | |
| station (i+1). You begin the journey with an empty tank at one of the gas stations. | |
| Return the starting gas station's index if you can travel around the circuit once in the clockwise direction, | |
| otherwise return -1. | |
| Note: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """" | |
| An integer has sequential digits if and only if each digit in the number is one more than the previous digit. | |
| Return a sorted list of all the integers in the range [low, high] inclusive that have sequential digits. | |
| Example 1: | |
| Input: low = 100, high = 300 | |
| Output: [123,234] |