Articles

  • Building skyline Outline

    Given N buildings in a x-axis,each building is a rectangle and can be represented by a triple (start, end, height),where start is the start position on x-axis, end is the end position on x-axis and height is the height of the building. Buildings may overlap if you see them from far away,find the outline of them. An outline can be represented by a triple, (start, end, height), where start is the start position on x-axis of the outline, end is the end position on x-axis and height is the height of the outline.

    Read More »

  • 218 - The Skyline Problem

    A city’s skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you are given the locations and height of all the buildings as shown on a cityscape photo (Figure A), write a program to output the skyline formed by these buildings collectively (Figure B).

    Read More »

  • Sliding Window Median

    Given an array of n integer, and a moving window(size k), move the window at each iteration from the start of the array, find the median of the element inside the window at each moving. (If there are even numbers in the array, return the N/2-th number after sorting the element in the window. )

    Read More »

  • 160 - Intersection of Two Linked Lists

    Write a program to find the node at which the intersection of two singly linked lists begins.

    Read More »

  • 234 - Palindrome Linked List

    Implement a function to check if a linked list is a palindrome.

    Read More »

  • 24 - Swap Nodes in Pairs

    Given a linked list, swap every two adjacent nodes and return its head.

    Read More »

  • 203 - Remove Linked List Elements

    Remove all elements from a linked list of integers that have value val.

    Read More »

  • 114 - Flatten Binary Tree to Linked List

    Given a binary tree, flatten it to a linked list in-place.

    Read More »

  • 17 - Letter Combinations of a Phone Number

    Given a digit string, return all possible letter combinations that the number could represent.

    Read More »

  • 25 - Reverse Nodes in k-Group

    Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.

    Read More »

  • Find the Weak Connected Component in the Directed Graph

    Find the number Weak Connected Component in the directed graph. Each node in the graph contains a label and a list of its neighbors. (a connected set of a directed graph is a subgraph in which any two vertices are connected by direct edge path.)

    Read More »

  • Trapping Rain Water II

    Given n x m non-negative integers representing an elevation map 2d where the area of each cell is 1 x 1, compute how much water it is able to trap after raining.

    Read More »

  • 42 - Trapping Rain Water

    Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.

    Read More »

  • 212 - Word Search II

    Given a matrix of lower alphabets and a dictionary. Find all words in the dictionary that can be found in the matrix. A word can start from any position in the matrix and go left/right/up/down to the adjacent position.

    Read More »

  • 79 - Word Search

    Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once.

    Read More »

  • The Smallest Difference

    Given two array of integers(the first array is array A, the second array is array B), now we are going to find a element in array A which is A[i], and another element in array B which is B[j], so that the difference between A[i] and B[j] (|A[i] - B[j]|) is as small as possible, return their smallest difference.

    Read More »

  • Sort Letters by Case

    Given a string which contains only letters. Sort it by lower case first and upper case second.

    Read More »

  • Sort Colors II

    Given an array of n objects with k different colors (numbered from 1 to k), sort them so that objects of the same color are adjacent, with the colors in the order 1, 2, ... k.

    Read More »

  • 75 - Sort Colors

    Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.

    Read More »

  • 71 - Simplify Path

    Given an absolute path for a file (Unix-style), simplify it.

    Read More »

  • 73 - Set Matrix Zeroes

    Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.

    Read More »

  • 61 - Rotate List

    Given a list, rotate the list to the right by k places, where k is non-negative.

    Read More »

  • 48 - Rotate Image

    You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise).

    Read More »

  • Rehashing

    The size of the hash table is not determinate at the very beginning. If the total size of keys is too large (e.g. size >= capacity / 10), we should double the size of the hash table and rehash every keys.

    Read More »

  • Number of Airplanes in the Sky

    Given an interval list which are flying and landing time of the flight. How many airplanes are on the sky at most?

    Read More »

  • 31 - Next Permutation

    Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order).

    Read More »

  • Minimum Adjustment Cost

    Given an integer array, adjust each integers so that the difference of every adjacent integers are not greater than a given number target. If the array before adjustment is A, the array after adjustment is B, you should minimize the sum of |A[i]-B[i]|

    Read More »

  • 209 - Minimum Size Subarray Sum

    Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum >= s. If there isn’t one, return -1 instead.

    Read More »

  • Maximum Subarray Difference

    Given an array with integers. Find two non-overlapping subarrays A and B, which |SUM(A) - SUM(B)| is the largest. Return the largest difference.

    Read More »

  • 152 - Maximum Product Subarray

    Find the contiguous subarray within an array (containing at least one number) which has the largest product.

    Read More »