This file contains 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
from abc import ABCMeta, abstractmethod | |
from enum import Enum | |
from typing import List, Optional | |
# Enum Definitions | |
RoomStyle = Enum("RoomStyle", "STANDARD DELUX SUITE") | |
RoomStatus = Enum("RoomStatus", "AVAILABLE RESERVED NOT_AVAILABLE OCCUPIED SERVICE_IN_PROGRESS") | |
BookingStatus = Enum("BookingStatus", "PENDING CONFIRMED CANCELED") |
This file contains 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 A, return the largest integer that only occurs once. | |
If no integer occurs once, return -1. | |
Example 1: | |
Input: [5,7,3,9,4,9,8,3,1] | |
Output: 8 | |
Explanation: |
This file contains 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
# Definition for singly-linked list. | |
# class ListNode: | |
# def __init__(self, val=0, next=None): | |
# self.val = val | |
# self.next = next | |
class Solution: | |
def isPalindrome(self, head: ListNode) -> bool: | |
numbers = [] | |
sentinel = head | |
while sentinel: |
This file contains 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 arr, return true if and only if it is a valid mountain array. | |
Recall that arr is a mountain array if and only if: | |
arr.length >= 3 | |
There exists some i with 0 < i < arr.length - 1 such that: | |
arr[0] < arr[1] < ... < arr[i - 1] < A[i] | |
arr[i] > arr[i + 1] > ... > arr[arr.length - 1] |
This file contains 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
""" | |
Implement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST): | |
BSTIterator(TreeNode root) Initializes an object of the BSTIterator class. The root of the BST is given as part of | |
the constructor. The pointer should be initialized to a non-existent number smaller than any element in the BST. | |
boolean hasNext() Returns true if there exists a number in the traversal to the right of the pointer, otherwise | |
returns false. | |
int next() Moves the pointer to the right, then returns the number at the pointer. | |
Notice that by initializing the pointer to a non-existent smallest number, the first call to next() will return the | |
smallest element in the BST. |
This file contains 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
""" | |
You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted | |
in adjacent plots. | |
Given an integer array flowerbed containing 0's and 1's, where 0 means empty and 1 means not empty, and an integer n, | |
return if n new flowers can be planted in the flowerbed without violating the no-adjacent-flowers rule. | |
Example 1: | |
Input: flowerbed = [1,0,0,0,1], n = 1 | |
Output: true |
This file contains 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 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 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 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? |
NewerOlder