# 問題

Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a cookie that the child will be content with; and each cookie j has a size sj. If sj >= gi, we can assign the cookie j to the child i, and the child i will be content. Your goal is to maximize the number of your content children and output the maximum number.

Note:
You may assume the greed factor is always positive.
You cannot assign more than one cookie to one child.

Example 1:

Example 2:

# 問題

For a web developer, it is very important to know how to design a web page’s size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L and width W satisfy the following requirements:

You need to output the length L and the width W of the web page you designed in sequence.

Example:

Note:

1. The given area won’t exceed 10,000,000 and is a positive integer
2. The web page’s width and length you designed must be positive integers.

# 答案

1. 我的笨方法
2. Top Solution的神方法

# 問題

Given a binary array, find the maximum number of consecutive 1s in this array.

Example 1:

Note:

• The input array will only contain `0` and `1`.
• The length of input array is a positive integer and will not exceed 10,000

# 問題

The `Employee` table holds all employees. Every employee has an Id, a salary, and there is also a column for the department Id.

The `Department` table holds all departments of the company.

Write a SQL query to find employees who have the highest salary in each of the departments. For the above tables, Max has the highest salary in the IT department and Henry has the highest salary in the Sales department.

# 答案

1. `JOIN`部門清單的時候先去把各部門最高薪資數字先撈了出來
2. (2017/01/16) 寫 185. Department Top Three Salaries 時後發現的方法

# 問題

Write a SQL query to delete all duplicate email entries in a table named `Person`, keeping only unique emails based on its smallest Id.

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

# 題目

Given a `Weather` table, write a SQL query to find all dates’ Ids with higher temperature compared to its previous (yesterday’s) dates.

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

# 答案

1. `Sub Query`
2. `Join`
3. `TO_DAYS`

# 問題

Given an array and a value, remove all instances of that value in place and return the new length.

Do not allocate extra space for another array, you must do this in place with constant memory.

The order of elements can be changed. It doesn’t matter what you leave beyond the new length.

Example:
Given input array nums = `[3,2,2,3]`, val = `3`

Your function should return length = 2, with the first two elements of nums being 2.

# 問題

Given an array `nums`, write a function to move all `0`‘s to the end of it while maintaining the relative order of the non-zero elements.

For example, given `nums = [0, 1, 0, 3, 12]`, after calling your function, `nums` should be `[1, 3, 12, 0, 0]`.

Note:

1. You must do this in-place without making a copy of the array.
2. Minimize the total number of operations.

# 問題

Suppose that a website contains two tables, the `Customers` table and the `Orders` table. Write a SQL query to find all customers who never order anything.

Table: `Customers`.

Table: `Orders`.

Using the above tables as example, return the following:

# 答案

1. `LEFT JOIN`
2. `Sub Query`

# [MySQL][LeetCode][Easy] 176. Second Highest Salary

Write a SQL query to get the second highest salary from the `Employee` table.

For example, given the above Employee table, the second highest salary is `200`. If there is no second highest salary, then the query should return `null`.

1. Sub Query
2. `DISTINCT` > 不重複
3. `GROUP BY` > 不重複