Articles

  • 463 - Island Perimeter

    You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells). The island doesn’t have “lakes” (water inside that isn’t connected to the water around the island). One cell is a square with side length 1. The grid is rectangular, width and height don’t exceed 100. Determine the perimeter of the island.

    Read More »

  • Reverse String

    Write a function that takes a string as input and returns the string reversed.

    Read More »

  • 496 - 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 Number of a number x in nums1 is the first greater number to its right in nums2. If it does not exist, output -1 for this number.

    Read More »

  • Reshape the Matrix

    In MATLAB, there is a very useful function called ‘reshape’, which can reshape a matrix into a new one with different size but keep its original data. You’re given a matrix represented by a two-dimensional array, and two positive integers r and c representing the row number and column number of the wanted reshaped matrix, respectively. The reshaped matrix need to be filled with all the elements of the original matrix in the same row-traversing order as they were. If the ‘reshape’ operation with given parameters is possible and legal, output the new reshaped matrix; Otherwise, output the original matrix.

    Read More »

  • 476 - Number Complement

    Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.

    Read More »

  • Keyboard Row

    Given a List of words, return the words that can be typed using letters of alphabet on only one row’s of American keyboard like the image below.

    Read More »

  • Reverse Words in a String III

    Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.

    Read More »

  • 461 - Hamming Distance

    The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, calculate the Hamming distance.

    Read More »

  • 561 - Array Partition 1

    Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), …, (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as possible.

    Read More »

  • Beautiful Soup Cheat Sheet

    Beautiful Soup Cheat Sheet

    Read More »

  • 507 - Perfect number

    We define the Perfect Number is a positive integer that is equal to the sum of all its positive divisors except itself. Now, given an integer n, write a function that returns true when it is a perfect number and false when it is not.

    Read More »

  • Add google analytics to your website

    Add google analytics to your website

    Read More »

  • HTML Tags

    Useful Html tags

    Read More »

  • 501 - Find Mode in Binary Search Tree

    Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST.

    Read More »

  • Build crawler using scrapy

    Build crawler using scrapy

    Read More »

  • Docker cheat sheet

    Docker cheet sheet

    Read More »

  • Deep Learning Notes

    Deep learning notes

    Read More »

  • Python notes

    Python notes

    Read More »

  • 333 - Largest BST Subtree

    Given a binary tree, find the largest subtree which is a Binary Search Tree (BST), where largest means subtree with largest number of nodes in it.

    Read More »

  • 331 - Verify Preorder Serialization of a Binary Tree

    Given a string of comma separated values, verify whether it is a correct preorder traversal serialization of a binary tree. Find an algorithm without reconstructing the tree.

    Read More »

  • 334 - Increasing Triplet Subsequence

    Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.

    Read More »

  • 332 - Reconstruct Itinerary

    Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK. Thus, the itinerary must begin with JFK.

    Read More »

  • 330 - Patching Array

    Given a sorted positive integer array nums and an integer n, add/patch elements to the array such that any number in range [1, n] inclusive can be formed by the sum of some elements in the array. Return the minimum number of patches required.

    Read More »

  • Find the difference between two set

    找出两个数组的差,比如A = [1,1,1,2,2,2], B = [2,2,3],在A出现在B不出现的集合是[1,1,1,2]

    Read More »

  • 360 - Sort Transformed Array

    Given an equation y = ax^2 + bx + c, and sorted array X, output sorted Y.

    Read More »

  • Longest Increasing Path in a Matrix

    Given an integer matrix, find the length of the longest increasing path. From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or move outside of the boundary (i.e. wrap-around is not allowed).

    Read More »

  • Top k elements with most occurrences

    Find k elements within a array with most occurrences.

    Read More »

  • 328 - Odd Even Linked List

    Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes. You should try to do it in place. The program should run in O(1) space complexity and O(nodes) time complexity.

    Read More »

  • 327 - Count of Range Sum

    Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive. Range sum S(i, j) is defined as the sum of the elements in nums between indices i and j (i ≤ j), inclusive.

    Read More »

  • Pick a random number from a BST

    Randomly pick a number from binary searach tree

    Read More »