The expected times of tosses until you see first HTH or HTT

The problem comes from a very famous Ted Talk:  You are flipping a fair coin. What is the expected times of tosses you need to see the first “HTH” appears? What is that for the first “HTT” appears? Suppose $latex N_1$ is the random variable which counts the number of flips till we get first …

Leetcode 31: Next Permutation

31. Next Permutation Total Accepted: 87393 Total Submissions: 313398 Difficulty: Medium Contributors: Admin 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). The replacement must be in-place, do not allocate …

Leetcode 64: Minimum Path Sum

https://leetcode.com/problems/minimum-path-sum/ 64. Minimum Path Sum Total Accepted: 91005 Total Submissions: 247256 Difficulty: Medium Contributors: Admin Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note: You can only move either down or right at any …

Leetcode 88: Merge Sorted Array

88. Merge Sorted Array Total Accepted: 129487 Total Submissions: 416385 Difficulty: Easy Contributors: Admin Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2. The …

Leetsql 196: Delete Duplicate Emails

196. Delete Duplicate Emails Total Accepted: 18532 Total Submissions: 97924 Difficulty: Easy Contributors: Admin Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id. +—-+——————+ | Id | Email | +—-+——————+ | 1 | john@example.com | | 2 | bob@example.com | …

Leetcode 254: Factor Combinations

254. Factor Combinations Total Accepted: 16019 Total Submissions: 40853 Difficulty: Medium Contributors: Admin Numbers can be regarded as product of its factors. For example, 8 = 2 x 2 x 2; = 2 x 4. Write a function that takes an integer n and return all possible combinations of its factors. Note: You may assume …

Leetsql 182: Duplicate Emails

182. Duplicate Emails  Total Accepted: 27110 Total Submissions: 73222 Difficulty: Easy Contributors: Admin Write a SQL query to find all duplicate emails in a table named Person. +—-+———+ | Id | Email | +—-+———+ | 1 | a@b.com | | 2 | c@d.com | | 3 | a@b.com | +—-+———+ For example, your query should …

Leetcode 221: Maximal Square

https://leetcode.com/problems/maximal-square/ 221. Maximal Square  Total Accepted: 44584 Total Submissions: 169331 Difficulty: Medium Contributors: Admin Given a 2D binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s and return its area. For example, given the following matrix: 1 0 1 0 0 1 0 1 1 1 1 1 1 1 …

Leetcode 211: Add and Search Word – Data structure design

211. Add and Search Word – Data structure design  Total Accepted: 37880 Total Submissions: 188966 Difficulty: Medium Contributors: Admin Design a data structure that supports the following two operations: void addWord(word) bool search(word) search(word) can search a literal word or a regular expression string containing only letters a-z or .. A . means it can …