180. Consecutive Numbers Total Accepted: 12576 Total Submissions: 52571 Difficulty: Medium Contributors: Admin Write a SQL query to find all numbers that appear at least three times consecutively. +—-+—–+ | Id | Num | +—-+—–+ | 1 | 1 | | 2 | 1 | | 3 | 1 | | 4 | 2 | …
Author Archives: czxttkl
Leetcode 178: Rank Score
https://leetcode.com/problems/rank-scores/ 178. Rank Scores Total Accepted: 13824 Total Submissions: 58154 Difficulty: Medium Contributors: Admin Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ranking. Note that after a tie, the next ranking number should be the next consecutive integer value. In other words, there …
Leetcode 3466: Moving Average from Data Stream
346. Moving Average from Data Stream Total Accepted: 11701 Total Submissions: 20717 Difficulty: Easy Contributors: Admin Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window. For example, MovingAverage m = new MovingAverage(3); m.next(1) = 1 m.next(10) = (1 + 10) / 2 m.next(3) = …
Continue reading “Leetcode 3466: Moving Average from Data Stream”
Leetcode 163: Missing Ranges
163. Missing Ranges Total Accepted: 19465 Total Submissions: 66232 Difficulty: Medium Contributors: Admin Given a sorted integer array where the range of elements are in the inclusive range [lower, upper], return its missing ranges. For example, given [0, 1, 3, 50, 75], lower = 0 and upper = 99, return ["2", "4->49", "51->74", "76->99"]. …
Leetcode 388: Longest Absolute File Path
388. Longest Absolute File Path Total Accepted: 11837 Total Submissions: 35565 Difficulty: Medium Contributors: Admin Suppose we abstract our file system by a string in the following manner: The string "dir\n\tsubdir1\n\tsubdir2\n\t\tfile.ext" represents: dir subdir1 subdir2 file.ext The directory dir contains an empty sub-directory subdir1 and a sub-directory subdir2 containing a file file.ext. The string "dir\n\tsubdir1\n\t\tfile1.ext\n\t\tsubsubdir1\n\tsubdir2\n\t\tsubsubdir2\n\t\t\tfile2.ext" …
Why do we use Poisson distribution or Negative Binomial distribution for regression?
Let’s say we have predictor variables (features) denoted as $latex X \in \mathbb{R}^n$ and response variable (label) $latex y$ whose underlying random variable is $latex Y$. If we want to fit an Ordinary Least Square (OLS) regression such that $latex y=WX+\epsilon$ where $latex \epsilon$ is an error term, then we have the following assumptions: strict exogenous: $latex E(\epsilon|X)=0$ …
Leetcode 198: House Robber
https://leetcode.com/problems/house-robber/ 198. House Robber Total Accepted: 101581 Total Submissions: 275668 Difficulty: Easy Contributors: Admin You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it …
Leetcode 298: Binary Tree Longest Consecutive Sequence
https://leetcode.com/problems/binary-tree-longest-consecutive-sequence/ Given a binary tree, find the length of the longest consecutive sequence path. The path refers to any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The longest consecutive path need to be from parent to child (cannot be the reverse). For example, 1 \ …
Continue reading “Leetcode 298: Binary Tree Longest Consecutive Sequence”
Leetcode 70: Climbing Stairs
70. Climbing Stairs Total Accepted: 139063 Total Submissions: 363734 Difficulty: Easy Contributors: Admin You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Code from math import sqrt …
Leetcode 258: Add Digits
258. Add Digits Total Accepted: 134747 Total Submissions: 269960 Difficulty: Easy Contributors: Admin Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one …