Continue working from home. It looks like LeetCode will continue this every day problem series. Let’s continue this one day one go problem for June LeetCoding Challenge.
May LeetCoding Challenge
The shelter-in-place order was extended to the end of May. LeetCode also published this May LeetCoding Challenge. Let’s continue this one day one go problem.
30-Day LeetCoding Challenge
It has almost been a year since I wrote my first leetcode blog post. Today LeetCode starts the 30-Day LeetCoding Challenge. Recently, I am learning golang, and I think praticing LeetCode is a good way to learn a new language, so I will use golang to solve these 30 LeetCode problems.
Patterns of Coding Problems
Introduction
After praticing many LeetCode problems, I think it’s very important to summarize different patterns for the coding problems. I found out Grokking the Coding Interview: Patterns for Coding Questions explains very well, but some of the contents is not free, so I will refernce its free part, and also adding the problems that I found online and grouping them into the corresponding patterns.
[LeetCode] 200. Number of Islands
Problem
Given a 2d grid map of ‘1’s (land) and ‘0’s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.
Example 1:
1 |
|
Example 2:
1 |
|
[LeetCode] 199. Binary Tree Right Side View
Problem
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.
Example:
1 |
|
[LeetCode] 198. House Robber
Problem
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 will automatically contact the police if two adjacent houses were broken into on the same night.
Given a list of non-negative integers representing the amount of money of each house, determine the maximum amount of money you can rob tonight without alerting the police.
Example 1:
1 |
|
Example 2:
1 |
|
[LeetCode] 197. Rising Temperature
Problem
Given a Weather
table, write a SQL query to find all dates’ Ids with higher temperature compared to its previous (yesterday’s) dates.
1 |
|
For example, return the following Ids for the above Weather
table:
1 |
|
[LeetCode] 196. Delete Duplicate Emails
Problem
Write a SQL query to delete all duplicate email entries in a table named Person
, keeping only unique emails based on its smallest Id.
1 |
|
For example, after running your query, the above Person
table should have the following rows:
1 |
|
Note:
Your output is the whole Person
table after executing your sql. Use delete statement.
[LeetCode] 195. Tenth Line
Problem
Given a text file file.txt
, print just the 10th line of the file.
Example:
Assume that file.txt
has the following content:
1 |
|
Your script should output the tenth line, which is:
1 |
|
Note:
- If the file contains less than 10 lines, what should you output?
- There’s at least three different solutions. Try to explore all possibilities.