Skip to content

Commit 09ecbc9

Browse files
committed
Make tests pass via mvn
1 parent 196529b commit 09ecbc9

File tree

96 files changed

+3967
-270
lines changed

Some content is hidden

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

96 files changed

+3967
-270
lines changed

.pmd

Lines changed: 1657 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Code Challenge
2+
3+
Code challenge solutions from different sources
4+
in Java programming language.
5+
6+
## Objective
7+
8+
I want to improve my problem-solving
9+
and technical skills and keep my
10+
competitive edge by covering the core
11+
programming concepts and exploring
12+
further.
13+
14+
Listed below are few topics which
15+
helps improve capabilities.
16+
17+
- Mathematics: Prime Number, Big Integer,
18+
Permutation, Number Theory, Factorial,
19+
Fibonacci, Sequences, Modulus
20+
21+
- Sorting: Bubble Sort, Quick Sort,
22+
Merge Sort, Selection Sort, Radix Sort,
23+
Bucket Sort
24+
25+
- Searching: Complete Search, Brute Force,
26+
Binary Search
27+
28+
- String Processing: String Matching,
29+
Pattern Matching
30+
31+
- Dynamic Programming: Longest Common
32+
Subsequence, Longest Increasing Subsequence,
33+
Edit Distance, 0/1 Knapsack, Coin Change,
34+
Matrix Chain Multiplication, Max Interval Sum
35+
36+
- Graph Traversal: Flood Fill, Floyd Warshal,
37+
MST, Max Bipartite Matching, Network Flow,
38+
Articulation Point
39+
40+
*“For me, great algorithms are the poetry of
41+
computation. Just like verse, they can be terse,
42+
allusive, dense, and even mysterious.
43+
But once unlocked, they cast a brilliant new
44+
light on some aspect of computing.”
45+
— Francis Sullivan*
46+
47+
*“An algorithm must be seen to be believed.”
48+
— Donald Knuth*
49+
50+
*“I will, in fact, claim that the difference
51+
between a bad programmer and a good one is
52+
whether he considers his code or his data
53+
structures more important.
54+
Bad programmers worry about the code.
55+
Good programmers worry about data structures and
56+
their relationships.” — Linus Torvalds*
57+
58+
*“Algorithms + Data Structures = Programs.”
59+
— Niklaus Wirth`*
60+
61+
## How to become good at code challenges?
62+
63+
*Observe, Introspect, Retrospect, Refactor, Repeat*
64+
65+
##### Understand The Basics
66+
Don't skip basics, mathematics, data structures
67+
and algorithms. Mathematics helps build a solution.
68+
The data structures are the tools and the algorithms
69+
are the techniques that are the arsenal that every
70+
good programmer must have, more the better. Else,
71+
you will only see `a hammer and a nail`.
72+
73+
##### Know The Process
74+
To solve the challenge, start with trivial, slow
75+
ideas to form a heuristic technique, and then
76+
improve towards creative, fast algorithms which
77+
could be solved with specific techniques. So just
78+
solve as you can first even the exponential solution
79+
if it works it's fine, be grateful.
80+
81+
Start by solving easy problems, then medium, and
82+
finally the difficult ones. Try different types
83+
of problems from different sources.
84+
85+
Learn from other's solution and compare with your
86+
own. Try to understand what other did differently
87+
and analyse what can be improved, both in your
88+
solutions. This will help add more
89+
dimensions to problem analysis and solutions ideas.
90+
91+
Improve your understanding by trying to answer
92+
Why was it done this way?.
93+
94+
##### Estimate The Complexity
95+
The time limit set for online tests is usually
96+
from 1 to 10 seconds. We can therefore estimate
97+
the expected complexity. During contests, we are
98+
often given a limit on the size of data, and
99+
therefore we can guess the time complexity within
100+
which the task should be solved. This is usually
101+
a great convenience because we can look for a
102+
solution that works in a specific complexity instead
103+
of worrying about a faster solution.
104+
105+
For example, if:
106+
- n <= 1 000 000, the expected time complexity is O(n) or O(nlogn)
107+
- n <= 10 000, the expected time complexity is O(n^2)
108+
- n <= 500, the expected time complexity is O(n^3)
109+
110+
Of course, these limits are not precise. They are
111+
just approximations, and will vary depending on the
112+
specific task.
113+
114+
115+
# Folders
116+
`resource` folder contains learning materials.

data/UUID.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
6a2f41a3-c54c-fce8-32d2-0324e1c32e22
2+
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
3+
[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}

data/tiny.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
S O R T E X A M P L E

pom.xml

Lines changed: 89 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,100 @@
77
<groupId>org.example</groupId>
88
<artifactId>codechallenge-java-pom</artifactId>
99
<version>1.0-SNAPSHOT</version>
10-
<dependencies>
11-
<dependency>
12-
<groupId>junit</groupId>
13-
<artifactId>junit</artifactId>
14-
<version>4.13.1</version>
15-
<scope>test</scope>
16-
</dependency>
17-
</dependencies>
1810

1911
<properties>
2012
<maven.compiler.source>11</maven.compiler.source>
2113
<maven.compiler.target>11</maven.compiler.target>
2214
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2315
</properties>
2416

17+
<dependencies>
18+
<dependency>
19+
<groupId>org.junit.platform</groupId>
20+
<artifactId>junit-platform-runner</artifactId>
21+
<version>1.9.0</version>
22+
<scope>test</scope>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.junit.jupiter</groupId>
26+
<artifactId>junit-jupiter-api</artifactId>
27+
<version>5.9.0</version>
28+
<scope>test</scope>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.junit.jupiter</groupId>
32+
<artifactId>junit-jupiter-params</artifactId>
33+
<version>5.9.0</version>
34+
<scope>test</scope>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.junit.jupiter</groupId>
38+
<artifactId>junit-jupiter-engine</artifactId>
39+
<version>5.9.0</version>
40+
<scope>test</scope>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.junit.jupiter</groupId>
44+
<artifactId>junit-jupiter-api</artifactId>
45+
<version>5.9.0</version>
46+
<scope>compile</scope>
47+
</dependency>
48+
</dependencies>
49+
50+
<build>
51+
<sourceDirectory>src</sourceDirectory>
52+
<plugins>
53+
<plugin>
54+
<groupId>org.codehaus.mojo</groupId>
55+
<artifactId>exec-maven-plugin</artifactId>
56+
<version>3.0.0</version>
57+
<configuration>
58+
<mainClass>main.java.com.oystercard.CLI</mainClass>
59+
</configuration>
60+
</plugin>
61+
<plugin>
62+
<groupId>org.apache.maven.plugins</groupId>
63+
<artifactId>maven-pmd-plugin</artifactId>
64+
<version>3.16.0</version>
65+
<configuration>
66+
<rulesets>
67+
<ruleset>/rulesets/java/braces.xml</ruleset>
68+
<ruleset>/rulesets/java/naming.xml</ruleset>
69+
</rulesets>
70+
</configuration>
71+
</plugin>
72+
73+
<plugin>
74+
<groupId>org.apache.maven.plugins</groupId>
75+
<artifactId>maven-surefire-plugin</artifactId>
76+
<version>2.22.0</version>
77+
<dependencies>
78+
<dependency>
79+
<groupId>org.junit.platform</groupId>
80+
<artifactId>junit-platform-surefire-provider</artifactId>
81+
<version>1.2.0</version>
82+
</dependency>
83+
</dependencies>
84+
</plugin>
85+
<plugin>
86+
<groupId>org.apache.maven.plugins</groupId>
87+
<artifactId>maven-failsafe-plugin</artifactId>
88+
<version>2.6</version>
89+
<executions>
90+
<execution>
91+
<id>integration-test</id>
92+
<goals>
93+
<goal>integration-test</goal>
94+
</goals>
95+
</execution>
96+
<!-- Uncomment/comment this in order to fail the build if any integration test fail -->
97+
<execution>
98+
<id>verify</id>
99+
<goals><goal>verify</goal></goals>
100+
</execution>
101+
</executions>
102+
</plugin>
103+
</plugins>
104+
</build>
105+
25106
</project>

resource/basics/0.math.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
TODO:
2+
- https://github.com/codeanit/til/issues/235
3+
- https://trello.com/c/AGYbTSda/117-mathematics
4+
- https://github.com/llSourcell/learn_math_fast
5+
6+
7+
8+
### Number Theory, Modular Arithmetic, Linear Alzebra
9+
10+
- https://www.hackerearth.com/practice/math/number-theory/basic-number-theory-1/tutorial/
11+
- https://www.hackerearth.com/practice/math/number-theory/basic-number-theory-2/tutorial/
12+
- https://www.khanacademy.org/computing/computer-science/cryptography#modarithmetic
13+
- https://artofproblemsolving.com/wiki/index.php/Modular_arithmetic/Intermediate
14+
- https://www.geeksforgeeks.org/binomial-coefficient-dp-9/
15+
- https://www.geeksforgeeks.org/compute-n-under-modulo-p/
16+
- https://betterexplained.com/articles/rethinking-arithmetic-a-visual-guide/
17+
- https://betterexplained.com/articles/learning-how-to-count-avoiding-the-fencepost-problem/
18+
- https://betterexplained.com/articles/how-to-develop-a-mindset-for-math/
19+
20+
21+
- https://en.wikipedia.org/wiki/Prime_number
22+
- https://en.wikipedia.org/wiki/Composite_number
23+
- https://www.mathsisfun.com/algebra/sequences-sums-arithmetic.html
24+
- https://www.mathsisfun.com/algebra/sequences-sums-geometric.html
25+
- https://primes.utm.edu/curios/page.php/1000000007.html
26+
27+
- https://en.wikipedia.org/wiki/Graph_theory
28+
- https://en.wikipedia.org/wiki/Adjacency_list
29+
- https://en.wikipedia.org/wiki/Adjacency_matrix
30+
- https://en.wikipedia.org/wiki/Incidence_matrix
31+
32+
- https://en.wikipedia.org/wiki/Modular_arithmetic
33+
- https://en.wikipedia.org/wiki/Euclidean_algorithm
34+
- https://en.wikipedia.org/wiki/Binomial_theorem
35+
- https://en.wikipedia.org/wiki/Binomial_coefficient
36+
- https://en.wikipedia.org/wiki/Numerical_linear_algebra
37+
- https://en.wikipedia.org/wiki/Combinatorial_optimization
38+
- https://en.wikipedia.org/wiki/Arithmetic_combinatorics
39+
- https://en.wikipedia.org/wiki/Additive_number_theory
40+
- https://en.wikipedia.org/wiki/Pseudo-polynomial_time
41+
- https://en.wikipedia.org/wiki/Convolution
42+
- https://en.wikipedia.org/wiki/Linear_regression
43+
- https://en.wikipedia.org/wiki/Reduction
44+
- https://en.wikipedia.org/wiki/Approximation_algorithm
45+
- https://en.wikipedia.org/wiki/Linear_programming
46+
- https://en.wikipedia.org/wiki/Nonlinear_programming
47+
48+
- https://glossary.informs.org/ver2/mpgwiki/index.php?title=Main_Page
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
TODO
2+
- https://trello.com/c/2fAVujDm/449-computer-science
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
> This is a work in progress!
2+
3+
4+
# Data Structure
5+
6+
##### Table of Content
7+
- [Data Structures](#data-structures)
8+
- [Array](#array)
9+
- [Linked List](#linked-list)
10+
- [Hash Table or Hash Map](#hash)
11+
- [Binary Tree](#binary-tree)
12+
- [Additional Resources](#additional-resources)
13+
14+
15+
### <a id="array"></a> Array
16+
#### Definition
17+
- Stores data elements based on an sequential, most commonly 0 based, index.
18+
- Based on [tuples](http://en.wikipedia.org/wiki/Tuple) from set theory.
19+
- They are one of the oldest, most commonly used data structures.
20+
21+
#### What you need to know
22+
- Optimal for indexing; bad at searching, inserting, and deleting (except at the end).
23+
- **Linear arrays**, or one dimensional arrays, are the most basic.
24+
- Are static in size, meaning that they are declared with a fixed size.
25+
- **Dynamic arrays** are like one dimensional arrays, but have reserved space for additional elements.
26+
- If a dynamic array is full, it copies its contents to a larger array.
27+
- **Multi dimensional arrays** nested arrays that allow for multiple dimensions such as an array of arrays providing a 2 dimensional spacial representation via x, y coordinates.
28+
29+
#### Time Complexity
30+
- Indexing: Linear array: `O(1)`, Dynamic array: `O(1)`
31+
- Search: Linear array: `O(n)`, Dynamic array: `O(n)`
32+
- Optimized Search: Linear array: `O(log n)`, Dynamic array: `O(log n)`
33+
- Insertion: Linear array: n/a, Dynamic array: `O(n)`
34+
35+
36+
### <a id="linked-list"></a> Linked List
37+
#### Definition
38+
- Stores data with **nodes** that point to other nodes.
39+
- Nodes, at its most basic it has one datum and one reference (another node).
40+
- A linked list _chains_ nodes together by pointing one node's reference towards another node.
41+
42+
#### What you need to know
43+
- Designed to optimize insertion and deletion, slow at indexing and searching.
44+
- **Doubly linked list** has nodes that also reference the previous node.
45+
- **Circularly linked list** is simple linked list whose **tail**, the last node, references the **head**, the first node.
46+
- **Stack**, commonly implemented with linked lists but can be made from arrays too.
47+
- Stacks are **last in, first out** (LIFO) data structures.
48+
- Made with a linked list by having the head be the only place for insertion and removal.
49+
- **Queues**, too can be implemented with a linked list or an array.
50+
- Queues are a **first in, first out** (FIFO) data structure.
51+
- Made with a doubly linked list that only removes from head and adds to tail.
52+
53+
#### Time Complexity
54+
- Indexing: Linked Lists: `O(n)`
55+
- Search: Linked Lists: `O(n)`
56+
- Optimized Search: Linked Lists: `O(n)`
57+
- Insertion: Linked Lists: `O(1)`
58+
59+
60+
### <a id="hash"></a> Hash Table or Hash Map
61+
#### Definition
62+
- Stores data with key value pairs.
63+
- **Hash functions** accept a key and return an output unique only to that specific key.
64+
- This is known as **hashing**, which is the concept that an input and an output have a one-to-one correspondence to map information.
65+
- Hash functions return a unique address in memory for that data.
66+
67+
#### What you need to know
68+
- Designed to optimize searching, insertion, and deletion.
69+
- **Hash collisions** are when a hash function returns the same output for two distinct inputs.
70+
- All hash functions have this problem.
71+
- This is often accommodated for by having the hash tables be very large.
72+
- Hashes are important for associative arrays and database indexing.
73+
74+
#### Time Complexity
75+
- Indexing: Hash Tables: `O(1)`
76+
- Search: Hash Tables: `O(1)`
77+
- Insertion: Hash Tables: `O(1)`
78+
79+
80+
### <a id="binary-tree"></a> Binary Tree
81+
#### Definition
82+
- Is a tree like data structure where every node has at most two children.
83+
- There is one left and right child node.
84+
85+
#### What you need to know
86+
- Designed to optimize searching and sorting.
87+
- A **degenerate tree** is an unbalanced tree, which if entirely one-sided, is essentially a linked list.
88+
- They are comparably simple to implement than other data structures.
89+
- Used to make **binary search trees**.
90+
- A binary tree that uses comparable keys to assign which direction a child is.
91+
- Left child has a key smaller than its parent node.
92+
- Right child has a key greater than its parent node.
93+
- There can be no duplicate node.
94+
- Because of the above it is more likely to be used as a data structure than a binary tree.
95+
96+
#### Time Complexity
97+
- Indexing: Binary Search Tree: `O(log n)`
98+
- Search: Binary Search Tree: `O(log n)`
99+
- Insertion: Binary Search Tree: `O(log n)`
100+
101+
102+
103+
104+
## <a id="additional-resources"></a>Additional Resources
105+
- https://github.com/codeanit/til/issues/150
106+
- https://www.hackerearth.com/practice/data-structures/arrays/1-d/tutorial
107+
- https://www.cs.cmu.edu/~adamchik/15-121/lectures
108+
- https://www.hackerearth.com/practice/data-structures
109+
- https://datastructures.maximal.io

0 commit comments

Comments
 (0)