Skip to content

Commit a7f7eba

Browse files
committed
Fix white space problems
1 parent d74cec6 commit a7f7eba

9 files changed

+85
-84
lines changed

algoexpert/merge-sorted-arrays.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ def test():
5858
],
5959
# fmt: off
6060
[
61-
-92, -78, -76, -74, -68, -66, -62, -49, -46, -40, -26, -23,
62-
-16, -8, 12, 20, 21, 28, 33, 33, 36, 38, 42, 43, 46, 46, 48,
61+
-92, -78, -76, -74, -68, -66, -62, -49, -46, -40, -26, -23,
62+
-16, -8, 12, 20, 21, 28, 33, 33, 36, 38, 42, 43, 46, 46, 48,
6363
50, 55, 79, 79, 81, 94
6464
],
6565
# fmt: on
@@ -77,9 +77,9 @@ def test():
7777
[-57, -43, -41, -18, -5, 74],
7878
],
7979
# fmt: off
80-
[
81-
-100, -93, -83, -83, -82, -57, -51, -43, -43, -41, -33, -33,
82-
-32, -32, -29, -18, -16, -15, -14, -11, -5, 0, 12, 23, 29,
80+
[
81+
-100, -93, -83, -83, -82, -57, -51, -43, -43, -41, -33, -33,
82+
-32, -32, -29, -18, -16, -15, -14, -11, -5, 0, 12, 23, 29,
8383
29, 40, 43, 50, 60, 70, 74, 76, 78, 80, 80,
8484
],
8585
# fmt: on

hackerrank/Java-priority-queue.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import java.util.ArrayList;
77
import java.util.List;
88
import java.util.Scanner;
9-
// import Priority Queue Collection Framework
10-
import java.util.*;
9+
// import Priority Queue Collection Framework
10+
import java.util.*;
1111
/*
1212
* Create the Student and Priorities classes here.
1313
*/
@@ -76,18 +76,18 @@ public ArrayList<Student> getStudents(List<String> events)
7676
public class Solution {
7777
private final static Scanner scan = new Scanner(System.in);
7878
private final static Priorities priorities = new Priorities();
79-
79+
8080
public static void main(String[] args) {
81-
int totalEvents = Integer.parseInt(scan.nextLine());
81+
int totalEvents = Integer.parseInt(scan.nextLine());
8282
List<String> events = new ArrayList<>();
83-
83+
8484
while (totalEvents-- != 0) {
8585
String event = scan.nextLine();
8686
events.add(event);
8787
}
88-
88+
8989
List<Student> students = priorities.getStudents(events);
90-
90+
9191
if (students.isEmpty()) {
9292
System.out.println("EMPTY");
9393
} else {

hackerrank/find-runner-up-score.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
# Tags: Array
77

88
n = int(input())
9-
i=0
10-
#takes input, splits it and then convert it into integer
11-
arr = list(map(int, input().split()))
9+
i = 0
10+
# takes input, splits it and then convert it into integer
11+
arr = list(map(int, input().split()))
1212
zes = max(arr)
1313

14-
while(i<n):
14+
while i < n:
1515
if zes == max(arr):
1616
arr.remove(max(arr))
17-
i+=1
17+
i += 1
1818

1919
print(max(arr))

hackerrank/merge-tools.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,22 @@
33
# https://www.hackerrank.com/challenges/merge-the-tools/problem?isFullScreen=true
44
# tags : String
55

6+
67
def merge_the_tools(string, k):
78
l = []
89
out = []
9-
for i in range (0, len(string), k):
10+
for i in range(0, len(string), k):
1011
c = ""
1112
for j in range(k):
1213
c += string[i + j]
1314
l.append(c)
14-
15+
1516
for elm in l:
16-
c= ""
17+
c = ""
1718
for j in range(k):
1819
if elm[j] not in c:
1920
c += elm[j]
2021
out.append(c)
21-
22+
2223
for res in out:
2324
print(res)

hackerrank/phone-book.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static void main(String[] args) {
2525
HashMap<String, Integer> phoneBook = new HashMap<String, Integer>();
2626
BufferedReader b = new BufferedReader(new InputStreamReader(
2727
System.in));
28-
no_of_entries = Integer.parseInt(b.readLine());
28+
no_of_entries = Integer.parseInt(b.readLine());
2929
while (i < no_of_entries) {
3030
name = b.readLine();
3131
number = Integer.parseInt(b.readLine());
@@ -39,7 +39,7 @@ public static void main(String[] args) {
3939
System.out.println("Not found");
4040
}
4141
} catch (Exception e) {
42-
42+
4343
}
4444
}
4545
}

leetcode/classes-more-than-5-students.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* https://leetcode.com/problems/classes-more-than-5-students/
66
*
77
* Tags: Database
8-
*
8+
*
99
* Group the students' records by class, return the class names for classes
1010
* that have 5 students or more.
1111
*/

leetcode/data-stream-as-disjoint-intervals.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ struct SummaryRanges {
1212
}
1313

1414

15-
/**
15+
/**
1616
* `&self` means the method takes an immutable reference.
1717
* If you need a mutable reference, change it to `&mut self` instead.
1818
*/
1919
impl SummaryRanges {
2020

2121
fn new() -> Self {
22-
22+
2323
}
24-
24+
2525
fn add_num(&self, value: i32) {
26-
26+
2727
}
28-
28+
2929
fn get_intervals(&self) -> Vec<Vec<i32>> {
30-
30+
3131
}
3232
}
3333

@@ -36,4 +36,4 @@ impl SummaryRanges {
3636
* let obj = SummaryRanges::new();
3737
* obj.add_num(value);
3838
* let ret_2: Vec<Vec<i32>> = obj.get_intervals();
39-
*/
39+
*/

leetcode/divide-two-integers.py

+52-52
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,81 @@
1+
# 29. Divide Two Integers
2+
# 🟠 Medium
3+
#
14
# https://leetcode.com/problems/divide-two-integers/
5+
#
6+
# Tags: Math - Bit Manipulation
27

3-
min_allowed = -2147483648
4-
max_allowed = 2147483647
8+
import timeit
59

6-
def to_binary_list(int_base_10):
7-
#convert an int base 10 to a list of 0's and 1's
8-
return [int(x) for x in bin(int_base_10)[2:]]
910

11+
# This solution is based on the fact that the quotient of a division is
12+
# equal to the number of times the divisor goes into the dividend.
13+
# We can use bitwise operations to get the quotient.
14+
#
15+
# Time complexity: O(log2(n)) - In each iteration we divide the initial
16+
# dividend by 2.
17+
# Space complexity: O(1) - We only store integer values.
18+
#
19+
# Runtime 50 ms Beats 9.81%
20+
# Memory 16.4 MB Beats 11.94%
1021
class Solution:
11-
# This solution is based on the fact that the quotient of a division is equal to the number
12-
# of times the divisor goes into the dividend.
13-
# We can use bitwise operations to get the quotient.
1422
def divide(self, dividend: int, divisor: int) -> int:
15-
param_dividend = dividend
16-
param_divisor = divisor
17-
1823
# Determine if the result will be negative
19-
negative = (dividend > 0 and divisor < 0) or (dividend < 0 and divisor > 0)
20-
24+
negative = (dividend > 0 and divisor < 0) or (
25+
dividend < 0 and divisor > 0
26+
)
2127
# The problem has a constraint of -2147483648 to 2147483647
22-
upper_bound = 1 << 31 if negative else (1 << 31) -1
23-
28+
upper_bound = 1 << 31 if negative else (1 << 31) - 1
2429
# Equivalent to using abs()
2530
dividend = 0 - dividend if dividend < 0 else dividend
2631
divisor = 0 - divisor if divisor < 0 else divisor
27-
2832
# Convert the dividend to a binary list
2933
dividend = [int(x) for x in bin(dividend)[2:]]
30-
3134
current_dividend = 0
3235
result = 0
33-
34-
print(f'\n» Dividing {param_dividend} by {param_divisor}\n')
3536
for next_digit in dividend:
3637
current_dividend = (current_dividend << 1) + next_digit
37-
38-
if(divisor <= current_dividend):
38+
if divisor <= current_dividend:
3939
current_dividend -= divisor
4040
new_digit = 1
4141
else:
4242
new_digit = 0
43-
4443
result = (result << 1) + new_digit
45-
print(f'current dividend: {current_dividend}; result: {result}; new digit: {new_digit}')
46-
4744
result = min(result, upper_bound)
48-
if(negative):
45+
if negative:
4946
result = 0 - result
50-
51-
print(f'\n» The result of {param_dividend} / {param_divisor} is {result}\n')
52-
5347
return result
5448

55-
56-
def divide_slow(self, dividend: int, divisor: int) -> int:
57-
sign = -1 if ((dividend < 0) ^ (divisor < 0)) else 1
58-
dividend = abs(dividend)
59-
divisor = abs(divisor)
60-
quotient = 0
61-
while dividend >= divisor:
62-
dividend -= divisor
63-
quotient += 1
64-
return quotient * sign
6549

66-
def test():
67-
sol = Solution()
68-
assert sol.divide(10, 3) == 3
69-
assert sol.divide(7, -3) == -2
70-
assert sol.divide(1, 1) == 1
71-
assert sol.divide(0, 1) == 0
72-
assert sol.divide(min_allowed, -1) == max_allowed
73-
assert sol.divide(1 << 31, 1) == max_allowed
74-
assert sol.divide(1 << 31, -17) == -126322567
75-
print('All tests passed!')
50+
def test():
51+
MIN_ALLOWED = -2147483648
52+
MAX_ALLOWED = 2147483647
53+
executors = [Solution]
54+
tests = [
55+
[1, 1, 1],
56+
[0, 1, 0],
57+
[10, 3, 3],
58+
[7, -3, -2],
59+
[1 << 31, 1, MAX_ALLOWED],
60+
[1 << 31, -17, -126322567],
61+
[MIN_ALLOWED, -1, MAX_ALLOWED],
62+
]
63+
for executor in executors:
64+
start = timeit.default_timer()
65+
for _ in range(1):
66+
for col, t in enumerate(tests):
67+
sol = executor()
68+
result = sol.divide(t[0], t[1])
69+
exp = t[2]
70+
assert result == exp, (
71+
f"\033[93m» {result} <> {exp}\033[91m for"
72+
+ f" test {col} using \033[1m{executor.__name__}"
73+
)
74+
stop = timeit.default_timer()
75+
used = str(round(stop - start, 5))
76+
cols = "{0:20}{1:10}{2:10}"
77+
res = cols.format(executor.__name__, used, "seconds")
78+
print(f"\033[92m» {res}\033[0m")
7679

77-
test()
7880

79-
# Uncomment the following lines to see print statements
80-
# sol=Solution()
81-
# sol.divide(1 << 31, 17)
81+
test()

leetcode/lists/.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Ignore temporary files
2-
tmp*
2+
tmp*

0 commit comments

Comments
 (0)