Skip to content

Commit

Permalink
Added 40 MySQL solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
RodneyShag committed Apr 8, 2017
1 parent decc8e7 commit 1f8a08b
Show file tree
Hide file tree
Showing 50 changed files with 484 additions and 39 deletions.
16 changes: 8 additions & 8 deletions 10 Days of Statistics/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 10 Days of Statistics
# 10 Days of Statistics

| Day | Challenge | Difficulty | Solution |
|:---:|:--------------------------------------------------------------------------------------------------------------------------:|:---------------:|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
Expand All @@ -7,12 +7,12 @@
| 1 | [Quartiles](https://www.hackerrank.com/challenges/s10-quartiles) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/10%20Days%20of%20Statistics/Day%201%20-%20Quartiles/Solution.java) |
| 1 | [Interquartile Range](https://www.hackerrank.com/challenges/s10-interquartile-range) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/10%20Days%20of%20Statistics/Day%201%20-%20Interquartile%20Range/Solution.java) |
| 1 | [Standard Deviation](https://www.hackerrank.com/challenges/s10-standard-deviation) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/10%20Days%20of%20Statistics/Day%201%20-%20Standard%20Deviation/Solution.java) |
| 2 | [Basic Probability](https://www.hackerrank.com/challenges/s10-mcq-1) | Multiple Choice | [Solution.txt](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/10%20Days%20of%20Statistics/Day%202%20-%20Basic%20Probability/Solution.txt) |
| 2 | [More Dice](https://www.hackerrank.com/challenges/s10-mcq-2) | Multiple Choice | [Solution.txt](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/10%20Days%20of%20Statistics/Day%202%20-%20More%20Dice/Solution.txt) |
| 2 | [Compound Event Probability](https://www.hackerrank.com/challenges/s10-mcq-3) | Multiple Choice | [Solution.txt](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/10%20Days%20of%20Statistics/Day%202%20-%20Compound%20Event%20Probability/Solution.txt) |
| 3 | [Conditional Probability](https://www.hackerrank.com/challenges/s10-mcq-4) | Multiple Choice | [Solution.txt](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/10%20Days%20of%20Statistics/Day%203%20-%20Conditional%20Probability/Solution.txt) |
| 3 | [Cards of the Same Suit](https://www.hackerrank.com/challenges/s10-mcq-5) | Multiple Choice | [Solution.txt](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/10%20Days%20of%20Statistics/Day%203%20-%20Cards%20of%20the%20Same%20Suit/Solution.txt) |
| 3 | [Drawing Marbles](https://www.hackerrank.com/challenges/s10-mcq-6) | Multiple Choice | [Solution.txt](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/10%20Days%20of%20Statistics/Day%203%20-%20Drawing%20Marbles/Solution.txt) |
| 2 | [Basic Probability](https://www.hackerrank.com/challenges/s10-mcq-1) | Multiple Choice | [Solution](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/10%20Days%20of%20Statistics/Day%202%20-%20Basic%20Probability/Solution.txt) |
| 2 | [More Dice](https://www.hackerrank.com/challenges/s10-mcq-2) | Multiple Choice | [Solution](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/10%20Days%20of%20Statistics/Day%202%20-%20More%20Dice/Solution.txt) |
| 2 | [Compound Event Probability](https://www.hackerrank.com/challenges/s10-mcq-3) | Multiple Choice | [Solution](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/10%20Days%20of%20Statistics/Day%202%20-%20Compound%20Event%20Probability/Solution.txt) |
| 3 | [Conditional Probability](https://www.hackerrank.com/challenges/s10-mcq-4) | Multiple Choice | [Solution](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/10%20Days%20of%20Statistics/Day%203%20-%20Conditional%20Probability/Solution.txt) |
| 3 | [Cards of the Same Suit](https://www.hackerrank.com/challenges/s10-mcq-5) | Multiple Choice | [Solution](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/10%20Days%20of%20Statistics/Day%203%20-%20Cards%20of%20the%20Same%20Suit/Solution.txt) |
| 3 | [Drawing Marbles](https://www.hackerrank.com/challenges/s10-mcq-6) | Multiple Choice | [Solution](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/10%20Days%20of%20Statistics/Day%203%20-%20Drawing%20Marbles/Solution.txt) |
| 4 | [Binomial Distribution I](https://www.hackerrank.com/challenges/s10-binomial-distribution-1) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/10%20Days%20of%20Statistics/Day%204%20-%20Binomial%20Distribution%20I/Solution.java) |
| 4 | [Binomial Distribution II](https://www.hackerrank.com/challenges/s10-binomial-distribution-2) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/10%20Days%20of%20Statistics/Day%204%20-%20Binomial%20Distribution%20II/Solution.java) |
| 4 | [Geometric Distribution I](https://www.hackerrank.com/challenges/s10-geometric-distribution-1) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/10%20Days%20of%20Statistics/Day%204%20-%20Geometric%20Distribution%20I/Solution.java) |
Expand All @@ -27,5 +27,5 @@
| 7 | [Pearson Correlation Coefficient I](https://www.hackerrank.com/challenges/s10-pearson-correlation-coefficient) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/10%20Days%20of%20Statistics/Day%207%20-%20Pearson%20Correlation%20Coefficient%20I/Solution.java) |
| 7 | [Spearman's Rank Correlation Coefficient](https://www.hackerrank.com/challenges/s10-spearman-rank-correlation-coefficient) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/10%20Days%20of%20Statistics/Day%207%20-%20Spearman%27s%20Rank%20Correlation%20Coefficient/Solution.java) |
| 8 | [Least Square Regression Line](https://www.hackerrank.com/challenges/s10-least-square-regression-line) | Easy | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/10%20Days%20of%20Statistics/Day%208%20-%20Least%20Square%20Regression%20Rate/Solution.java) |
| 8 | [Pearson Correlation Coefficient II](https://www.hackerrank.com/challenges/s10-mcq-7) | Multiple Choice | [Solution.txt](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/10%20Days%20of%20Statistics/Day%208%20-%20Pearson%20Correlation%20Coefficient%20II/Solution.txt) |
| 8 | [Pearson Correlation Coefficient II](https://www.hackerrank.com/challenges/s10-mcq-7) | Multiple Choice | [Solution](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/10%20Days%20of%20Statistics/Day%208%20-%20Pearson%20Correlation%20Coefficient%20II/Solution.txt) |
| 9 | [Multiple Linear Regression](https://www.hackerrank.com/challenges/s10-multiple-linear-regression) | Medium | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/10%20Days%20of%20Statistics/Day%209%20-%20Multiple%20Linear%20Regression/Solution.java) |
2 changes: 1 addition & 1 deletion 30 Days of Code/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 30 Days of Code
# 30 Days of Code

| Day | Challenge | Difficulty | Solution |
|:---:|:-------------------------------------------------------------------------------------------------------:|:----------:|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
Expand Down
14 changes: 11 additions & 3 deletions Algorithms/Greedy/Marc's Cakewalk/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,28 @@
import java.util.Arrays;
import java.util.Collections;

// Algorithm: Eat the largest cupcakes first

// Is this a Greedy Algorithm? No.
//
// A greedy algorithm makes the "locally optimal choice at each stage with the hope of finding a
// global optimum" - Wikipedia. Our solution actually makes the locally LEAST optimal choice at
// each stage, so it is not a greedy algorithm. Is there a name for this approach? I'm not sure,
// but maybe we can call it a "reverse-greedy algorithm"

// Time Complexity: O(n log n)
public class Solution {
public static void main(String[] args) {
public static void main(String [] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
Integer [] calories = new Integer[n]; // Use Integer instead of int to make sorting in decreasing order simpler
Integer [] calories = new Integer[n]; // Use Integer instead of int to make sorting in simpler
for (int i = 0; i < n; i++){
calories[i] = scan.nextInt();
}
scan.close();
System.out.println(minimumMiles(calories));
}

/* Eat the largest cupcakes first */
private static long minimumMiles(Integer [] calories) {
Arrays.sort(calories, Collections.reverseOrder());
long multiplier = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
import java.util.Scanner;
import java.util.Arrays;

// Algorithm: Sort the array and compare adjacent pairs

// Greedy algorithm? No

// A greedy algorithm makes "the locally optimal choice at each
// stage with the hope of finding a global optimum" - Wikipedia

public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Expand All @@ -17,7 +24,6 @@ public static void main(String[] args) {
System.out.println(minAbsoluteDifference(array));
}

/* Uses Greedy Approach */
private static int minAbsoluteDifference(int [] array) {
Arrays.sort(array);
int min = Integer.MAX_VALUE;
Expand Down
2 changes: 1 addition & 1 deletion Algorithms/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Algorithms
# Algorithms

| Subdomain | Challenge | Difficulty | Solution |
|:-----------------------:|:-----------------------------------------------------------------------------------------------------------------------------------:|:----------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
Expand Down
2 changes: 1 addition & 1 deletion Cracking the Coding Interview/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Cracking the Coding Interview
# Cracking the Coding Interview

| Topic | Challenge | Difficulty | Solution |
|:---------------------:|:--------------------------------------------------------------------------------------------------------:|:----------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
Expand Down
8 changes: 4 additions & 4 deletions Data Structures/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Data Structures
# Data Structures

| Subdomain | Challenge | Difficulty | Solution |
|:---------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------:|:----------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
Expand Down Expand Up @@ -60,9 +60,9 @@
| Disjoint Set | [Components in a graph](https://www.hackerrank.com/challenges/components-in-graph) | Medium | Coming Soon! |
| Disjoint Set | [Kundu and Tree](https://www.hackerrank.com/challenges/kundu-and-tree) | Hard | Coming Soon! |
| Disjoint Set | [Super Maximum Cost Queries](https://www.hackerrank.com/challenges/maximum-cost-queries) | Hard | Coming Soon! |
| Multiple Choice | [Data Structures MCQ 1](https://www.hackerrank.com/challenges/how-well-do-you-know-trees) | Hard | [Solution.txt](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Multiple%20Choice/Data%20Structures%20MCQ%201/Solution.txt) |
| Multiple Choice | [Data Structures MCQ 2](https://www.hackerrank.com/challenges/are-you-an-expert-on-data-structures) | Hard | [Solution.txt](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Multiple%20Choice/Data%20Structures%20MCQ%202/Solution.txt) |
| Multiple Choice | [Data Structures MCQ 3](https://www.hackerrank.com/challenges/are-you-an-expert-on-data-structures-1) | Hard | [Solution.txt](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Multiple%20Choice/Data%20Structures%20MCQ%203/Solution.txt) |
| Multiple Choice | [Data Structures MCQ 1](https://www.hackerrank.com/challenges/how-well-do-you-know-trees) | Hard | [Solution](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Multiple%20Choice/Data%20Structures%20MCQ%201/Solution.txt) |
| Multiple Choice | [Data Structures MCQ 2](https://www.hackerrank.com/challenges/are-you-an-expert-on-data-structures) | Hard | [Solution](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Multiple%20Choice/Data%20Structures%20MCQ%202/Solution.txt) |
| Multiple Choice | [Data Structures MCQ 3](https://www.hackerrank.com/challenges/are-you-an-expert-on-data-structures-1) | Hard | [Solution](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Multiple%20Choice/Data%20Structures%20MCQ%203/Solution.txt) |
| Trie | [Contacts](https://www.hackerrank.com/challenges/contacts) | Medium | [Solution.java](https://github.com/rshaghoulian/HackerRank-solutions/blob/master/Data%20Structures/Trie/Contacts/Solution.java) |
| Trie | [No Prefix Set](https://www.hackerrank.com/challenges/no-prefix-set) | Hard | Coming Soon! |
| Advanced | [Kindergarten Adventures](https://www.hackerrank.com/challenges/kindergarten-adventures) | Medium | Coming Soon! |
Expand Down
2 changes: 1 addition & 1 deletion Java/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Java
# Java

| Subdomain | Challenge | Difficulty | Solution |
|:---------------------------:|:------------------------------------------------------------------------------------------------------------------------:|:----------:|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
Expand Down
Loading

0 comments on commit 1f8a08b

Please sign in to comment.