Articles

  • 890 - Find And Replace Pattern

    Given a list of strings words and a string pattern, return a list of words[i] that match pattern. You may return the answer in any order.

    Read More »

  • 34 - Find First And Last Position Of Element In Sorted Array

    Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value.

    Read More »

  • 1047 - Remove All Adjacent Duplicates In String

    You are given a string s consisting of lowercase English letters. A duplicate removal consists of choosing two adjacent and equal letters and removing them.

    Read More »

  • 1209 - Remove All Adjacent Duplicates In String Ii

    You are given a string s and an integer k, a k duplicate removal consists of choosing k adjacent and equal letters from s and removing them, causing the left and the right side of the deleted substring to concatenate together.

    Read More »

  • 576 - Out Of Boundary Paths

    There is an m x n grid with a ball. The ball is initially at the position [startRow, startColumn]. You are allowed to move the ball to one of the four adjacent cells in the grid (possibly out of the grid crossing the grid boundary). You can apply at most maxMove moves to the ball.

    Read More »

  • 1472 - Design Browser History

    You have a browser of one tab where you start on the homepage and you can visit another url, get back in the history number of steps or move forward in the history number of steps.

    Read More »

  • 1429 - First Unique Number

    You have a queue of integers, you need to retrieve the first unique integer in the queue.

    Read More »

  • 346 - Moving Average From Data Stream

    Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window.

    Read More »

  • 876 - Middle Of The Linked List

    Given the head of a singly linked list, return the middle node of the linked list. If there are two middle nodes, return the second middle node.

    Read More »

  • 973 - K Closest Points To Origin

    We have a list of points on the plane. Find the K closest points to the origin (0, 0). You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in.)

    Read More »

  • 1192 - Critical Connections In A Network

    There are n servers numbered from 0 to n-1 connected by undirected server-to-server connections forming a network where connections[i] = [a, b] represents a connection between servers a and b. Any server can reach any other server directly or indirectly through the network. A critical connection is a connection that, if removed, will make some server unable to reach some other server. Return all critical connections in the network in any order.

    Read More »

  • 896 - Monotonic Array

    An array is monotonic if it is either monotone increasing or monotone decreasing. An array A is monotone increasing if for all i <= j, A[i] <= A[j]. An array A is monotone decreasing if for all i <= j, A[i] >= A[j]. Return true if and only if the given array A is monotonic.

    Read More »

  • 689 - Maximum Sum Of 3 Non Overlapping Subarrays

    In a given array nums of positive integers, find three non-overlapping subarrays with maximum sum. Each subarray will be of size k, and we want to maximize the sum of all 3*k entries. Return the result as a list of indices representing the starting position of each interval (0-indexed). If there are multiple answers, return the lexicographically smallest one.

    Read More »

  • 785 - Is Graph Bipartite

    Given an undirected graph, return true if and only if it is bipartite. Recall that a graph is bipartite if we can split it’s set of nodes into two independent subsets A and B such that every edge in the graph has one node in A and another node in B. The graph is given in the following form: graph[i] is a list of indexes j for which the edge between nodes i and j exists. Each node is an integer between 0 and graph.length - 1. There are no self edges or parallel edges: graph[i] does not contain i, and it doesn’t contain any element twice.

    Read More »

  • 824 - Goat Latin

    A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and uppercase letters only. We would like to convert the sentence to “Goat Latin” (a made-up language similar to Pig Latin.) The rules of Goat Latin are as follows:

    Read More »

  • 636 - Exclusive Time Of Functions

    On a single threaded CPU, we execute some functions. Each function has a unique id between 0 and N-1. We store logs in timestamp order that describe when a function is entered or exited. A function’s exclusive time is the number of units of time spent in this function. Note that this does not include any recursive calls to child functions. The CPU is single threaded which means that only one function is being executed at a given time unit. Return the exclusive time of each function, sorted by their function id.

    Read More »

  • 523 - Continuous Subarray Sum

    Given a list of non-negative numbers and a target integer k, write a function to check if the array has a continuous subarray of size at least 2 that sums up to a multiple of k, that is, sums up to n*k where n is also an integer.

    Read More »

  • 987 - Vertical Order Traversal Of A Binary Tree

    Given a binary tree, return the vertical order traversal of its nodes values. For each node at position (X, Y), its left and right children respectively will be at positions (X-1, Y-1) and (X+1, Y-1). Running a vertical line from X = -infinity to X = +infinity, whenever the vertical line touches some nodes, we report the values of the nodes in order from top to bottom (decreasing Y coordinates). If two nodes have the same position, then the value of the node that is reported first is the value that is smaller. Return an list of non-empty reports in order of X coordinate. Every report will have a list of values of nodes.

    Read More »

  • 833 - Find And Replace In String

    To some string S, we will perform some replacement operations that replace groups of letters with new ones (not necessarily the same size). Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.

    Read More »

  • 588 - Design In Memory File System

    Design an in-memory file system to simulate the following functions:

    Read More »

  • 889 - Construct Binary Tree From Preorder And Postorder Traversal

    Return any binary tree that matches the given preorder and postorder traversals. Values in the traversals pre and post are distinct positive integers.

    Read More »

  • 1011 - Capacity To Ship Packages Within D Days

    A conveyor belt has packages that must be shipped from one port to another within D days. The i-th package on the conveyor belt has a weight of weights[i]. Each day, we load the ship with packages on the conveyor belt (in the order given by weights). We may not load more weight than the maximum weight capacity of the ship. Return the least weight capacity of the ship that will result in all the packages on the conveyor belt being shipped within D days.

    Read More »

  • 844 - Backspace String Compare

    Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character.

    Read More »

  • 1197 - Minimum Knight Moves

    In an infinite chess board with coordinates from -infinity to +infinity, you have a knight at square [0, 0]. A knight has 8 possible moves it can make, as illustrated below. Each move is two squares in a cardinal direction, then one square in an orthogonal direction.

    Read More »

  • 363 - Max Sum Of Rectangle No Larger Than K

    Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix such that its sum is no larger than k.

    Read More »

  • 951 - Flip Equivalent Binary Trees

    For a binary tree T, we can define a flip operation as follows: choose any node, and swap the left and right child subtrees. A binary tree X is flip equivalent to a binary tree Y if and only if we can make X equal to Y after some number of flip operations. Write a function that determines whether two binary trees are flip equivalent. The trees are given by root nodes root1 and root2.

    Read More »

  • 1146 - Snapshot Array

    Implement a SnapshotArray that supports the following interface:

    Read More »

  • 489 - Robot Room Cleaner

    Given a robot cleaner in a room modeled as a grid. Each cell in the grid can be empty or blocked. The robot cleaner with 4 given APIs can move forward, turn left or turn right. Each turn it made is 90 degrees. When it tries to move into a blocked cell, its bumper sensor detects the obstacle and it stays on the current cell. Design an algorithm to clean the entire room using only the 4 given APIs shown below.

    Read More »

  • 1219 - Path With Maximum Gold

    In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions:

    Read More »

  • 752 - Open The Lock

    You have a lock in front of you with 4 circular wheels. Each wheel has 10 slots: ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’. The wheels can rotate freely and wrap around: for example we can turn ‘9’ to be ‘0’, or ‘0’ to be ‘9’. Each move consists of turning one wheel one slot. The lock initially starts at ‘0000’, a string representing the state of the 4 wheels. You are given a list of deadends dead ends, meaning if the lock displays any of these codes, the wheels of the lock will stop turning and you will be unable to open it. Given a target representing the value of the wheels that will unlock the lock, return the minimum total number of turns required to open the lock, or -1 if it is impossible.

    Read More »