Student Attendance Record I

Title: Positions of Large Groups Source: leetcode.com You are given a string representing an attendance record for a student. The record only contains the following three characters: ‘A’ : Absent. ‘L’ : Late. ‘P’ : Present. A student could be rewarded if his attendance record doesn’t contain more than one ‘A’ (absent) or more than ...

Positions of Large Groups

Title: Positions of Large Groups Source: leetcode.com In a string S of lowercase letters, these letters form consecutive groups of the same character. For example, a string like S = “abbxxxxzyy” has the groups “a”, “bb”, “xxxx”, “z” and “yy”. Call a group large if it has 3 or more characters. We would like the ...

N-ary Tree PreOrder Traversal 2

Title: N-ary Tree Preorder Traversal Source: leetcode.com Given an n-ary tree, return the preorder traversal of its nodes’ values. For example, given a 3-ary tree: Return its preorder traversal as: [1,3,5,6,2,4]. Note: Recursive solution is trivial, could you do it iteratively? You could find another explanation/ problem related to Preorder Traversal here. Java solution (Recursive) ...

Image Smoother

Title: Image SmootherSource: leetcode.com Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother to make the gray scale of each cell becomes the average gray scale (rounding down) of all the 8 surrounding cells and itself. If a cell has less than 8 surrounding cells, ...

Matrix Transpose

Title: Transpose MatrixSource: leetcode.com Code to return transpose of a matrix. Given a matrix A, return the transpose of A. The transpose of a matrix is the matrix flipped over it’s main diagonal, switching the row and column indices of the matrix. Example 1: Input: [[1,2,3],[4,5,6],[7,8,9]] Output: [[1,4,7],[2,5,8],[3,6,9]] Example 2: Input: [[1,2,3],[4,5,6]] Output: [[1,4],[2,5],[3,6]] Python ...

Longest Palindrome

Title: Longest PalindromeSource: leetcode.com Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters. This is case sensitive, for example “Aa” is not considered a palindrome here. Note: Assume the length of given string will not exceed 1,010. Example 1: Input: ...

Goat Latin

Title: Goat Latin Source: leetcode.com 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: If a word begins with ...

Buddy Strings

Title: Buddy Strings Source: leetcode.com Given two strings A and B of lowercase letters, return true if and only if we can swap two letters in A so that the result equals B. Example 1: Input: A = “ab”, B = “ba” Output: true Example 2: Input: A = “ab”, B = “ab” Output: false ...

A Moving Ball with HTML5 canvas

A Moving Ball with HTML5 canvas
Hello Everyone! Today we are going to learn something about the HTML5 canvas tag. And the result we are trying to achieve is shown here at codepan, It would be a ball moving around a designated area. The complete code is also available here on github. So let’s begin and create an HTML file called ...

Maximum Product of Word Lengths

Title: Maximum Product of Word Lengths Source: leetcode.com Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word will contain only lower case letters. If no such two words exist, return 0. Example 1: Input: [“abcw”,”baz”,”foo”,”bar”,”xtfn”,”abcdef”] Output: ...