题目描述
Given an array, rotate the array to the right by k steps, where k is non-negative.
Example 1:
1 | Input: [1,2,3,4,5,6,7] and k = 3 |
Example 2:
1 | Input: [-1,-100,3,99] and k = 2 |
题目描述
Given an array, rotate the array to the right by k steps, where k is non-negative.
Example 1:
1 | Input: [1,2,3,4,5,6,7] and k = 3 |
Example 2:
1 | Input: [-1,-100,3,99] and k = 2 |
题目描述
Say you have an array for which the i-th element is the price of a given stock on day i.
Design an algorithm to find the maximum profit. You may complete at most k transactions.
Note:
You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).
Example 1:
1 | Input: [2,4,1], k = 2 |
Example 2:
1 | Input: [3,2,6,5,0,3], k = 2 |
题目描述
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: “ACGAATTCCG”. When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.
Write a function to find all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule.
Example:
1 | Input: s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT" |
题目描述
The Employee
table holds all employees. Every employee has an Id, a salary, and there is also a column for the department Id.
1 | +----+-------+--------+--------------+ |
The Department
table holds all departments of the company.
1 | +----+----------+ |
Write a SQL query to find employees who have the highest salary in each of the departments. For the above tables, your SQL query should return the following rows (order of rows does not matter).
1 | +------------+----------+--------+ |
Explanation:
Max and Jim both have the highest salary in the IT department and Henry has the highest salary in the Sales department.
题目描述
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
.
1 | +----+-------+ |
Table: Orders
.
1 | +----+------------+ |
Using the above tables as example, return the following:
1 | +-----------+ |
题目描述
Write a SQL query to find all duplicate emails in a table named Person
.
1 | +----+---------+ |
For example, your query should return the following for the above table:
1 | +---------+ |
题目描述
The Employee
table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.
1 | +----+-------+--------+-----------+ |
Given the Employee
table, write a SQL query that finds out employees who earn more than their managers. For the above table, Joe is the only employee who earns more than his manager.
1 | +----------+ |
题目描述
Given a list of non negative integers, arrange them such that they form the largest number.
Example 1:
1 | Input: [10,2] |
Example 2:
1 | Input: [3,30,34,5,9] |
题目描述
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 should be no “holes” between ranks.
1 | +----+-------+ |
For example, given the above Scores
table, your query should generate the following report (order by highest score):
1 | +-------+------+ |
题目描述
Write a SQL query to get the nth highest salary from the Employee
table.
1 | +----+--------+ |
For example, given the above Employee table, the nth highest salary where n = 2 is 200
. If there is no nth highest salary, then the query should return null
.
1 | +------------------------+ |