Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4509d34

Browse files
add 614
1 parent 5646ae5 commit 4509d34

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ Your ideas/fixes/algorithms are more than welcome!
596596
|627|[Swap Salary](https://leetcode.com/problems/swap-salary/)|[Solution](../master/database/_627.sql) | | | Easy |
597597
|620|[Not Boring Movies](https://leetcode.com/problems/not-boring-movies/)|[Solution](../master/database/_620.sql) | | | Easy |
598598
|619|[Biggest Single Number](https://leetcode.com/problems/biggest-single-number/)|[Solution](../master/database/_619.sql) | | | Easy |
599+
|614|[Second Degree Follower](https://leetcode.com/problems/second-degree-follower/)|[Solution](../master/database/_614.sql) | | | Medium | Inner Join
599600
|613|[Shortest Distance in a Line](https://leetcode.com/problems/shortest-distance-in-a-line/)|[Solution](../master/database/_613.sql) | || Easy|
600601
|612|[Shortest Distance in a Plane](https://leetcode.com/problems/shortest-distance-in-a-plane/)|[Solution](../master/database/_612.sql) | || Medium|
601602
|610|[Triangle Judgement](https://leetcode.com/problems/triangle-judgement/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_610.java) | | | Easy |

database/_614.sql

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--614. Second Degree Follower
2+
--In facebook, there is a follow table with two columns: followee, follower.
3+
--
4+
--Please write a sql query to get the amount of each follower’s follower if he/she has one.
5+
--
6+
--For example:
7+
--
8+
--+-------------+------------+
9+
--| followee | follower |
10+
--+-------------+------------+
11+
--| A | B |
12+
--| B | C |
13+
--| B | D |
14+
--| D | E |
15+
--+-------------+------------+
16+
--should output:
17+
--+-------------+------------+
18+
--| follower | num |
19+
--+-------------+------------+
20+
--| B | 2 |
21+
--| D | 1 |
22+
--+-------------+------------+
23+
--Explaination:
24+
--Both B and D exist in the follower list, when as a followee, B's follower is C and D, and D's follower is E. A does not exist in follower list.
25+
--Note:
26+
--Followee would not follow himself/herself in all cases.
27+
--Please display the result in follower's alphabet order.
28+
29+
select f1.follower, count(distinct f2.follower) as num
30+
from follow f1
31+
inner join follow f2 on f1.follower = f2.followee
32+
group by f1.follower

0 commit comments

Comments
 (0)