262. Trips and Users Total Accepted: 6774 Total Submissions: 43127 Difficulty: Hard Contributors: Admin The Trips table holds all taxi trips. Each trip has a unique Id, while Client_Id and Driver_Id are both foreign keys to the Users_Id at the Users table. Status is an ENUM type of (‘completed’, ‘cancelled_by_driver’, ‘cancelled_by_client’). +—-+———–+———–+———+——————–+———-+ | Id | …
Author Archives: czxttkl
Sql Cheat Sheet
http://www.w3schools.com/sql/sql_quickref.asp http://files.zeroturnaround.com/pdf/zt_sql_cheat_sheet.pdf
Leetsql 185: Department Top Three Salaries
185. Department Top Three Salaries Total Accepted: 8926 Total Submissions: 57724 Difficulty: Hard Contributors: Admin The Employee table holds all employees. Every employee has an Id, and there is also a column for the department Id. +—-+——-+——–+————–+ | Id | Name | Salary | DepartmentId | +—-+——-+——–+————–+ | 1 | Joe | 70000 | 1 …
Continue reading “Leetsql 185: Department Top Three Salaries”
LeetSql 177: Nth Highest Salary
177. Nth Highest Salary Total Accepted: 12870 Total Submissions: 80808 Difficulty: Medium Contributors: Admin Write a SQL query to get the nth highest salary from the Employee table. +—-+——–+ | Id | Salary | +—-+——–+ | 1 | 100 | | 2 | 200 | | 3 | 300 | +—-+——–+ For example, given the …
Leetcode 40: Combination Sum II
40. Combination Sum II Total Accepted: 89506 Total Submissions: 294097 Difficulty: Medium Contributors: Admin Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. Each number in C may only be used once in the combination. Note: All numbers (including …
Leetcode 341: Flatten Nested List Iterator
341. Flatten Nested List Iterator Total Accepted: 20339 Total Submissions: 55207 Difficulty: Medium Contributors: Admin Given a nested list of integers, implement an iterator to flatten it. Each element is either an integer, or a list — whose elements may also be integers or other lists. Example 1:Given the list [[1,1],2,[1,1]], By calling next repeatedly …
Continue reading “Leetcode 341: Flatten Nested List Iterator”
Leetcode 27: Remove Element
27. Remove Element Total Accepted: 154492 Total Submissions: 426032 Difficulty: Easy Contributors: Admin 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 …
Leetcode 29: Divide Two Integers
29. Divide Two Integers Total Accepted: 82624 Total Submissions: 519755 Difficulty: Medium Contributors: Admin Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. Code (Naive) import sys class Solution(object): def divide(self, dividend, divisor): “”” :type dividend: int :type divisor: int :rtype: int “”” if not divisor: …
Leetcode 21: Merge Two Sorted Lists
21. Merge Two Sorted Lists Total Accepted: 167826 Total Submissions: 448665 Difficulty: Easy Contributors: Admin Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. Code # Definition for singly-linked list. # class ListNode(object): # def __init__(self, …
Leetcode 14: Longest Common Prefix
14. Longest Common Prefix Total Accepted: 131998 Total Submissions: 438812 Difficulty: Easy Contributors: Admin Write a function to find the longest common prefix string amongst an array of strings. Code class Solution(object): def longestCommonPrefix(self, strs): “”” :type strs: List[str] :rtype: str “”” if not strs: return “” prefix = “” for k in xrange(len(strs[0])): …