# LeetCode 132 Pattern

LeetCode 132 Pattern Given a sequence of n integers a1, a2, ..., an, a 132 pattern is a subsequence ai, aj, ak such that i < j < k and ai < ak < aj. Design an algorithm that takes a list of n numbers as input and checks whether there is a... Read More

# LeetCode Next Greater Element II

LeetCode Next Greater Element II Given a circular array (the next element of the last element is the first element of the array), print the Next Greater Number for every element. The Next Greater Number of a number x is the first greater number to its... Read More

# LeetCode Next Greater Element I

LeetCode Next Greater Element I You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1's elements in the corresponding places of nums2. The Next Greater... Read More

# LeetCode Implement Stack using Queues

LeetCode Implement Stack using Queues Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. top() -- Get the top element. empty() -- Return whether the stack... Read More

# LeetCode Implement Queue using Stacks

LeetCode Implement Queue using Stacks Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of queue. pop() -- Removes the element from in front of queue. peek() -- Get the front element. empty() -- Return... Read More

# LeetCode Kth Largest Element in an Array

LeetCode Kth Largest Element in an Array Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For example, Given and k = 2, return 5. Note: You may assume k is... Read More

# LeetCode Min Stack

LeetCode Min Stack Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. top() -- Get the top element. getMin() --... Read More

# LeetCode Evaluate Reverse Polish Notation

LeetCode Evaluate Reverse Polish Notation Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. Some examples: -> ((2 + 1) * 3) -> 9 ... Read More

# LeetCode Binary Search Tree Iterator

LeetCode Binary Search Tree Iterator Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST. Calling next() will return the next smallest number in the BST. Note: next() and hasNext() should... Read More

# LeetCode Insert Delete GetRandom O(1) - Duplicates allowed

LeetCode Insert Delete GetRandom O(1) - Duplicates allowed Design a data structure that supports all following operations in average O(1) time. Note: Duplicate elements are allowed. insert(val): Inserts an item val to the collection. remove(val):... Read More