James Blog


  • Home

  • Archives

  • Tags

  • Search

June LeetCoding Challenge

Posted on 06-01-2020 | In LeetCode

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.

Read more »

May LeetCoding Challenge

Posted on 05-01-2020 | In LeetCode

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.

Read more »

30-Day LeetCoding Challenge

Posted on 04-01-2020 | In LeetCode

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.

Read more »

Patterns of Coding Problems

Posted on 11-18-2019 | In Tech

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.

Read more »

[LeetCode] 200. Number of Islands

Posted on 11-17-2019 | In LeetCode

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
2
3
4
5
6
7
Input:
11110
11010
11000
00000

Output: 1

Example 2:

1
2
3
4
5
6
7
Input:
11000
11000
00100
00011

Output: 3
Read more »

[LeetCode] 199. Binary Tree Right Side View

Posted on 11-16-2019 | In LeetCode

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
2
3
4
5
6
7
8
9
Input: [1,2,3,null,5,null,4]
Output: [1, 3, 4]
Explanation:

   1            <---
 /   \
2     3         <---
 \     \
  5     4       <---
Read more »

[LeetCode] 198. House Robber

Posted on 11-15-2019 | In LeetCode

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
2
3
4
Input: [1,2,3,1]
Output: 4
Explanation: Rob house 1 (money = 1) and then rob house 3 (money = 3).
             Total amount you can rob = 1 + 3 = 4.

Example 2:

1
2
3
4
Input: [2,7,9,3,1]
Output: 12
Explanation: Rob house 1 (money = 2), rob house 3 (money = 9) and rob house 5 (money = 1).
             Total amount you can rob = 2 + 9 + 1 = 12.
Read more »

[LeetCode] 197. Rising Temperature

Posted on 11-14-2019 | In LeetCode

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
2
3
4
5
6
7
8
+---------+------------------+------------------+
| Id(INT) | RecordDate(DATE) | Temperature(INT) |
+---------+------------------+------------------+
|       1 |       2015-01-01 |               10 |
|       2 |       2015-01-02 |               25 |
|       3 |       2015-01-03 |               20 |
|       4 |       2015-01-04 |               30 |
+---------+------------------+------------------+

For example, return the following Ids for the above Weather table:

1
2
3
4
5
6
+----+
| Id |
+----+
|  2 |
|  4 |
+----+
Read more »

[LeetCode] 196. Delete Duplicate Emails

Posted on 11-13-2019 | In LeetCode

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
2
3
4
5
6
7
8
+----+------------------+
| Id | Email            |
+----+------------------+
| 1  | john@example.com |
| 2  | bob@example.com  |
| 3  | john@example.com |
+----+------------------+
Id is the primary key column for this table.

For example, after running your query, the above Person table should have the following rows:

1
2
3
4
5
6
+----+------------------+
| Id | Email            |
+----+------------------+
| 1  | john@example.com |
| 2  | bob@example.com  |
+----+------------------+

Note:

Your output is the whole Person table after executing your sql. Use delete statement.

Read more »

[LeetCode] 195. Tenth Line

Posted on 11-12-2019 | In LeetCode

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
2
3
4
5
6
7
8
9
10
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10

Your script should output the tenth line, which is:

1
Line 10

Note:

  1. If the file contains less than 10 lines, what should you output?
  2. There’s at least three different solutions. Try to explore all possibilities.
Read more »
1 2 3 … 23
James Huang

James Huang

226 posts
4 categories
48 tags
GitHub LinkedIn Twitter Portfolio
© 2025 James Huang
Powered by Jekyll
Theme - NexT.Muse