Skip to content

Commit 3eaaa66

Browse files
authored
Merge branch 'master' into 430
2 parents 7af08a8 + 2980913 commit 3eaaa66

File tree

1,110 files changed

+34298
-6717
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,110 files changed

+34298
-6717
lines changed

Diff for: .github/workflows/gradle.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Java CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
permissions: read-all
10+
jobs:
11+
build-linux:
12+
name: build-linux
13+
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0
20+
- name: Set up JDK 11
21+
uses: actions/setup-java@v3
22+
with:
23+
distribution: 'temurin'
24+
java-version: '11'
25+
cache: 'gradle'
26+
- name: Build with Gradle
27+
run: chmod +x gradlew && ./gradlew build

Diff for: README.md

+1,441-1,026
Large diffs are not rendered by default.

Diff for: build.gradle

+23-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,22 @@ apply plugin: 'checkstyle'
44
group = 'com.fishercoder'
55
version = '1.0-SNAPSHOT'
66

7+
javadoc.options.encoding = 'UTF-8'
8+
compileJava.options.encoding = 'UTF-8'
9+
710
checkstyle {
811
//include ( '**/*.java')
912
configFile = file("${rootDir}/fishercoder_checkstyle.xml")
1013
}
1114

15+
sourceSets {
16+
main {
17+
java {
18+
srcDir 'src/fishercoder'
19+
}
20+
}
21+
}
22+
1223
description = """"""
1324

1425
sourceCompatibility = 1.8
@@ -21,12 +32,22 @@ repositories {
2132

2233
dependencies {
2334
compile 'com.google.code.gson:gson:2.8.0'
24-
compile 'junit:junit:4.12'
2535
compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.0'
26-
testCompile group: 'junit', name: 'junit', version:'4.12'
2736

37+
// TODO: to remove Junit4 after all tests are migrated to Junit5
38+
compile 'junit:junit:4.13'
39+
testCompile "junit:junit:4.13.1"
40+
41+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
42+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
43+
44+
testCompile("org.assertj:assertj-core:3.11.1")
2845
compileOnly 'org.projectlombok:lombok:1.18.12'
2946
annotationProcessor 'org.projectlombok:lombok:1.18.12'
3047
testCompileOnly 'org.projectlombok:lombok:1.18.12'
3148
testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
3249
}
50+
51+
test {
52+
useJUnitPlatform()
53+
}

Diff for: database/_1113.sql

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
select extra as report_reason, count(distinct(post_id)) as report_count from Actions where action_date = '2019-07-04' and action = 'report' group by extra;

Diff for: database/_1142.sql

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
--# Write your MySQL query statement below
2+
select ifnull(round(count(distinct session_id)/count(distinct user_id), 2), 0.00)
3+
as average_sessions_per_user
4+
from Activity
5+
where activity_date between '2019-06-28' and '2019-07-27';

Diff for: database/_1211.sql

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
select query_name, round(avg(rating/position), 2) as quality, round(avg(rating < 3) * 100, 2) as poor_query_percentage from Queries group by query_name;

Diff for: database/_1371.sql

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
--# Write your MySQL query statement below
2+
select b.employee_id, b.name, count(*) as reports_count, round(avg(a.age)) as average_age
3+
from Employees a join Employees b on a.reports_to = b.employee_id
4+
group by b.employee_id
5+
order by b.employee_id

Diff for: database/_1393.sql

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
select stock_name, sum(
2+
case
3+
when operation = 'Buy' then -price
4+
else price
5+
end
6+
) as capital_gain_loss from Stocks group by stock_name;

Diff for: database/_1421.sql

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- # Write your MySQL query statement below
2+
select q.id, q.year, ifnull(n.npv, 0) as npv from Queries as q left join NPV as n on q.id = n.id and q.year = n.year

Diff for: database/_1435.sql

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- # Write your MySQL query statement below
2+
with groupedBy as (
3+
select "[0-5>" as bin, 0 as minDuration, 60*5 as maxDuration
4+
union all
5+
select "[5-10>" as bin, 60*5 as minDuration, 60*10 as maxDuration
6+
union all
7+
select "[10-15>" as bin, 60*10 as minDuration, 60*15 as maxDuration
8+
union all
9+
select "15 or more" as bin, 60*15 as minDuration, 2147483647 as maxDuration
10+
)
11+
12+
select bin, count(session_id) as total from groupedBy
13+
left join Sessions on duration >= minDuration and duration < maxDuration
14+
group by bin;

Diff for: database/_1445.sql

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--# Write your MySQL query statement below
2+
select sale_date as SALE_DATE, (o.sold_num - a.sold_num) as DIFF from Sales a join Sales o using(sale_date) group by sale_date order by sale_date

Diff for: database/_1511.sql

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
select customer_id, name from Customers
2+
join Orders using(customer_id)
3+
join Product using(product_id)
4+
group by customer_id
5+
having
6+
sum(if(left(order_date, 7) = '2020-06', quantity, 0) * price) >= 100
7+
and
8+
sum(if(left(order_date, 7) = '2020-07', quantity, 0) * price) >= 100;

Diff for: database/_1527.sql

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--# Write your MySQL query statement below
2+
select * from Patients where conditions like "DIAB1%" or conditions like "% DIAB1%";

Diff for: database/_1565.sql

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--# Write your MySQL query statement below
2+
select LEFT(order_date, 7) as month, count(order_id) as order_count, count(distinct(customer_id)) as customer_count from Orders where invoice > 20 group by month;

Diff for: database/_1571.sql

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--# Write your MySQL query statement below
2+
select name as warehouse_name, sum(units * Width * Length * Height) as volume from Warehouse w left join Products p on w.product_id = p.product_id group by name;

Diff for: database/_1581.sql

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--# Write your MySQL query statement below
2+
select customer_id as customer_id, count(*) as count_no_trans from Visits where visit_id not in (select distinct visit_id from Transactions) group by customer_id;

Diff for: database/_1587.sql

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--# Write your MySQL query statement below
2+
select u.name, sum(t.amount) as balance from Users u join Transactions t on u.account = t.account group by u.account having balance > 10000;

Diff for: database/_1596.sql

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--credit: https://leetcode.com/problems/the-most-frequently-ordered-products-for-each-customer/discuss/861257/simple-and-easy-solution-using-window-function
2+
3+
select customer_id, product_id, product_name from
4+
(
5+
select o.customer_id, o.product_id, p.product_name,
6+
rank() over (partition by customer_id order by count(o.product_id) desc) as ranking
7+
from Orders o
8+
join Products p
9+
on o.product_id = p.product_id
10+
group by customer_id, product_id
11+
) tmp
12+
where ranking = 1
13+
order by customer_id, product_id

Diff for: database/_1607.sql

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--# Write your MySQL query statement below
2+
select seller_name from Seller as SELLER_NAME where seller_id not in (
3+
select distinct(seller_id) from Orders where sale_date between '2020-01-01' and '2020-12-31'
4+
) order by seller_name;

Diff for: database/_1623.sql

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--# Write your MySQL query statement below
2+
select a.student_name as member_A,
3+
b.student_name as member_B,
4+
c.student_name as member_C
5+
from SchoolA a cross join SchoolB b cross join SchoolC c where a.student_name != b.student_name and
6+
a.student_id != b.student_id and
7+
b.student_name != c.student_name and
8+
b.student_id != c.student_id and
9+
a.student_name != c.student_name and
10+
a.student_id != c.student_id;

Diff for: database/_1633.sql

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--# Write your MySQL query statement below
2+
select contest_id, round((count(distinct(user_id)) * 100 / (select count(*) from Users)), 2) as percentage from Register group by contest_id order by percentage desc, contest_id;

Diff for: database/_1661.sql

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
select s.machine_id, round(avg(e.timestamp - s.timestamp), 3) as processing_time
2+
from Activity s join Activity e
3+
on s.machine_id = e.machine_id and s.process_id = e.process_id and s.activity_type = 'start' and e.activity_type = 'end' group by s.machine_id;

Diff for: database/_1667.sql

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--# Write your MySQL query statement below
2+
select user_id, concat(UCASE(LEFT(name, 1)), LCASE(SUBSTRING(name, 2))) as name from Users order by user_id;

Diff for: database/_1677.sql

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--# Write your MySQL query statement below
2+
select name, sum(rest) as rest, sum(paid) as paid, sum(canceled) as canceled, sum(refunded) as refunded from Product join Invoice using (product_id) group by name order by name;

Diff for: database/_1683.sql

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--# Write your MySQL query statement below
2+
select tweet_id from Tweets where length(content) > 15;

Diff for: database/_1693.sql

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--# Write your MySQL query statement below
2+
select date_id, make_name, count(distinct(lead_id)) as unique_leads,
3+
count(distinct(partner_id)) as unique_partners from DailySales group by date_id, make_name;

Diff for: database/_1709.sql

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--# Write your MySQL query statement below
2+
with diff_table as (
3+
select user_id, datediff(lead(visit_date, 1, '2021-1-1') over (partition by user_id order by visit_date), visit_date) as diff from UserVisits
4+
)
5+
6+
select user_id, max(diff) as biggest_window from diff_table group by user_id order by user_id

Diff for: database/_1729.sql

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--# Write your MySQL query statement below
2+
select user_id, count(follower_id) as followers_count from followers group by user_id order by user_id;

Diff for: database/_175.sql

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
select Person.FirstName,
2-
Person.LastName,
3-
Address.City,
4-
Address.State
5-
from Person
6-
left join Address on Person.PersonId = Address.PersonId;
1+
# Write your MySQL query statement below
2+
select p.firstName, p.lastName, a.city, a.state
3+
from Person as p left join Address as a on p.personId = a.personId

Diff for: database/_1757.sql

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--# Write your MySQL query statement below
2+
select product_id from Products where low_fats = 'Y' and recyclable = 'Y';

Diff for: database/_1777.sql

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- # Write your MySQL query statement below
2+
select
3+
product_id,
4+
max(case when store = 'store1' then price end) as store1,
5+
max(case when store = 'store2' then price end) as store2,
6+
max(case when store = 'store3' then price end) as store3
7+
from
8+
Products
9+
group by
10+
product_id

Diff for: fishercoder_checkstyle.xml

-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@
5555
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
5656
</module>
5757

58-
<module name="AvoidStarImport"/>
59-
6058
<module name="OneTopLevelClass"/>
6159

6260
<module name="NoLineWrap"/>

Diff for: javascript/_1146.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Author: Phuong Lam
3+
*/
4+
5+
/**
6+
* @param {number} length
7+
*/
8+
var SnapshotArray = function (length) {
9+
this.changes = {}
10+
this.snapShots = []
11+
}
12+
13+
/**
14+
* @param {number} index
15+
* @param {number} val
16+
* @return {void}
17+
*/
18+
SnapshotArray.prototype.set = function (index, val) {
19+
this.changes[index] = val
20+
}
21+
22+
/**
23+
* @return {number}
24+
*/
25+
SnapshotArray.prototype.snap = function () {
26+
this.snapShots.push(this.changes)
27+
this.changes = {}
28+
return this.snapShots.length - 1
29+
}
30+
31+
/**
32+
* @param {number} index
33+
* @param {number} snap_id
34+
* @return {number}
35+
*/
36+
SnapshotArray.prototype.get = function (index, snap_id) {
37+
while (snap_id >= 0 && this.snapShots[snap_id][index] === undefined) snap_id--
38+
if (snap_id >= 0) return this.snapShots[snap_id][index]
39+
return 0
40+
}
41+
42+
/**
43+
* Your SnapshotArray object will be instantiated and called as such:
44+
* var obj = new SnapshotArray(length)
45+
* obj.set(index,val)
46+
* var param_2 = obj.snap()
47+
* var param_3 = obj.get(index,snap_id)
48+
*/

Diff for: javascript/_1637.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Author: Phuong Lam
2+
3+
/**
4+
* @param {number[][]} points
5+
* @return {number}
6+
*/
7+
var maxWidthOfVerticalArea = function(points) {
8+
const sortedX = points
9+
.map((point) => {
10+
return point[0]
11+
})
12+
.sort((a, b) => {
13+
if (a < b) return -1
14+
if (a > b) return 1
15+
return 0
16+
})
17+
var max = 0
18+
for (let i = 0; i < sortedX.length - 1; i++) {
19+
const d = sortedX[i + 1] - sortedX[i]
20+
if (d > max) max = d
21+
}
22+
return max
23+
};

Diff for: javascript/_1658.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Author: Phuong Lam
2+
3+
/**
4+
* @param {number[]} nums
5+
* @param {number} x
6+
* @return {number}
7+
*/
8+
var minOperations = function (nums, x) {
9+
const total = nums.reduce((a, b) => a + b)
10+
if (total === x) return nums.length
11+
12+
var sum = 0
13+
var head = 0
14+
var max = -1
15+
for (var tail = 0; tail < nums.length; tail++) {
16+
sum += nums[tail]
17+
while (sum > total - x) {
18+
sum -= nums[head]
19+
head++
20+
}
21+
if (sum === total - x) max = Math.max(max, tail - head + 1)
22+
}
23+
24+
return max === -1 ? -1 : nums.length - max
25+
}

0 commit comments

Comments
 (0)