Skip to content

Commit

Permalink
Added 10 solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
RodneyShag committed Sep 11, 2017
1 parent 1b2f98d commit ba2c707
Show file tree
Hide file tree
Showing 81 changed files with 517 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.HashMap;

class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
/* Save input as entries in a HashMap */
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
Expand Down
2 changes: 1 addition & 1 deletion 30 Days of Code/Day 11 - 2D Arrays/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.Scanner;

public class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int arr[][] = new int[6][6];
for (int row = 0; row < 6; row++) {
Expand Down
2 changes: 1 addition & 1 deletion 30 Days of Code/Day 13 - Abstract Classes/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void display() {
}

public class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String title = sc.nextLine();
String author = sc.nextLine();
Expand Down
2 changes: 1 addition & 1 deletion 30 Days of Code/Day 20 - Sorting/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class Solution {
private static int swaps = 0;

public static void main(String [] args) {
public static void main(String[] args) {
/* Save input */
Scanner scan = new Scanner(System.in);
int size = scan.nextInt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// 2) x ^ 0 = x
// 3) XOR is commutative and associative
public class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
/* Read input */
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
Expand Down
2 changes: 1 addition & 1 deletion Algorithms/Bit Manipulation/Counter game/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
// Number - 1 : 10110011 and the number of 1s is 5

public class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
while (T-- > 0) {
Expand Down
2 changes: 1 addition & 1 deletion Algorithms/Bit Manipulation/Lonely Integer/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// 2) x ^ 0 = x
// 3) XOR is commutative and associative
public class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
/* Save input */
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
Expand Down
2 changes: 1 addition & 1 deletion Algorithms/Bit Manipulation/Maximizing XOR/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// Notice that we never directly calculate the values of A and B

public class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int L = scan.nextInt();
int R = scan.nextInt();
Expand Down
2 changes: 1 addition & 1 deletion Algorithms/Bit Manipulation/Sansa and XOR/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// Time Complexity: O(n)

public class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
while (T-- > 0) {
Expand Down
2 changes: 1 addition & 1 deletion Algorithms/Bit Manipulation/Sum vs XOR/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// 2^(number of 0s) (where ^ is exponentiation in this case) to count all combinations.

public class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
/* Save input */
Scanner scan = new Scanner(System.in);
long n = scan.nextLong();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// Must use "long" instead of "int" to avoid integer overflow

public class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
/* Save input */
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
Expand Down
2 changes: 1 addition & 1 deletion Algorithms/Greedy/Beautiful Pairs/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Solution {

private static final int MAX_NUM = 1000; // max value of any number in array

public static void main(String [] args) {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
int [] bucketA = new int[MAX_NUM + 1];
Expand Down
2 changes: 1 addition & 1 deletion Algorithms/Search/Connected Cells in a Grid/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Solution {
private static int rows; // here for convenience
private static int cols; // here for convenience

public static void main(String [] args) {
public static void main(String[] args) {
/* Save input grid */
Scanner scan = new Scanner(System.in);
rows = scan.nextInt();
Expand Down
2 changes: 1 addition & 1 deletion Algorithms/Search/Ice Cream Parlor/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Time Complexity: O(n)
// Space Complexity: O(n)
public class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
while (t-- > 0) {
Expand Down
2 changes: 1 addition & 1 deletion Algorithms/Sorting/Luck Balance/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// Space Complexity: O(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();
int K = scan.nextInt();
Expand Down
2 changes: 1 addition & 1 deletion Algorithms/Sorting/Marc's Cakewalk/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

// 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 simpler
Expand Down
2 changes: 1 addition & 1 deletion Algorithms/Sorting/The Full Counting Sort/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// - used StringBuffer to do 1 output to console instead of multiple outputs

public class Solution {
public static void main(String [] args) throws IOException {
public static void main(String[] args) throws IOException {
final int maxValue = 100;

/* Create HashMap with empty "buckets" to put Strings into */
Expand Down
2 changes: 1 addition & 1 deletion Algorithms/Strings/CamelCase/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.Scanner;

public class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String str = scan.next();
scan.close();
Expand Down
2 changes: 1 addition & 1 deletion Algorithms/Strings/Gemstones/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class Solution {
private static final int NUM_ELEMENTS = 26;

public static void main(String [] args) {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();

Expand Down
2 changes: 1 addition & 1 deletion Algorithms/Strings/Mars Exploration/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.Scanner;

public class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String str = scan.next();
scan.close();
Expand Down
2 changes: 1 addition & 1 deletion Algorithms/Strings/Super Reduced String/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// through it properly since iteration order is opposite that of a Stack.

public class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
/* Save input */
Scanner scan = new Scanner(System.in);
String str = scan.next();
Expand Down
2 changes: 1 addition & 1 deletion Algorithms/Strings/The Love-Letter Mystery/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// all palindromic pairs.

public class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
while (T-- > 0) {
Expand Down
2 changes: 1 addition & 1 deletion Algorithms/Strings/Two Characters/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class Solution {

public static final int NUM_LETTERS = 26;

public static void main(String [] args) {
public static void main(String[] args) {
/* Save input */
Scanner scan = new Scanner(System.in);
int length = scan.nextInt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Time Complexity: O(n)
// Space Complexity: O(n)
public class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
while (t-- > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Solution {
private static int rows; // here for convenience
private static int cols; // here for convenience

public static void main(String [] args) {
public static void main(String[] args) {
/* Save input grid */
Scanner scan = new Scanner(System.in);
rows = scan.nextInt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// Time Complexity: O(n log n)
// Space Complexity: O(n)
public class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int testcases = scan.nextInt();
while (testcases-- > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class Solution {
private static int swaps = 0;

public static void main(String [] args) {
public static void main(String[] args) {
/* Save input */
Scanner scan = new Scanner(System.in);
int size = scan.nextInt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Player {
}

class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Time Complexity: O(n)
// Space Complexity: O(1) by doing an "in place" rotation
public class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
/* Save input */
Scanner scan = new Scanner(System.in);
int size = scan.nextInt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Solution {
private static PriorityQueue<Integer> maxHeap = new PriorityQueue<>(Collections.reverseOrder()); // keeps track of the SMALL numbers
private static PriorityQueue<Integer> minHeap = new PriorityQueue<>(); // keeps track of the LARGE numbers

public static void main(String [] args) {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int [] array = new int[n];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// 2) x ^ 0 = x
// 3) XOR is commutative and associative
public class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
/* Read input */
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// Must use "long" instead of "int" to avoid integer overflow

public class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
/* Save input */
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class Solution {
private static HashMap<Integer, Integer> cache = new HashMap<>();

public static void main(String [] args) {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int testcases = scan.nextInt();
cache.put(0, 1); // base case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Time Complexity: O(n)
// Space Complexity: O(1)
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();
scan.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.Scanner;

public class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int p = scan.nextInt();
while (p-- > 0) {
Expand Down
2 changes: 1 addition & 1 deletion Data Structures/Arrays/2D Array - DS/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class Solution {

public static void main(String [] args) {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int arr[][] = new int[6][6];
for (int row = 0; row < 6; row++) {
Expand Down
2 changes: 1 addition & 1 deletion Data Structures/Arrays/Algorithmic Crush/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// Time Complexity: O(n + m)
// Space Complexity: O(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();
int M = scan.nextInt();
Expand Down
2 changes: 1 addition & 1 deletion Data Structures/Arrays/Arrays - DS/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.Scanner;

public class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
/* Save input */
Scanner scan = new Scanner(System.in);
int size = scan.nextInt();
Expand Down
2 changes: 1 addition & 1 deletion Data Structures/Arrays/Left Rotation/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Time Complexity: O(n)
// Space Complexity: O(1) by doing an "in place" rotation
public class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
/* Save input */
Scanner scan = new Scanner(System.in);
int size = scan.nextInt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Solution {
private static PriorityQueue<Integer> maxHeap = new PriorityQueue<>(Collections.reverseOrder()); // keeps track of the SMALL numbers
private static PriorityQueue<Integer> minHeap = new PriorityQueue<>(); // keeps track of the LARGE numbers

public static void main(String [] args) {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int [] array = new int[n];
Expand Down
2 changes: 1 addition & 1 deletion Data Structures/Trees/Square-Ten Tree/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// - To achieve linear runtime, we need an algorithm that splits up these giant numbers into portions and processes them separately. A great way to do this is to split by level, as done below.
// - This was a very difficult problem. You must have both linear runtime and efficient code to pass all testcases.
public class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
/* Read and save input */
Scanner scan = new Scanner(System.in);
String strL = new BigInt(scan.next()).subtract(BigInt.ONE).toString(); // subtract 1 since it's [L,R] inclusive
Expand Down
2 changes: 1 addition & 1 deletion Data Structures/Trees/Swap Nodes [Algo]/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Main trick: Repesent our tree as a 1-D array

public class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
/* Create tree */
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static Node insert(Node root, int data) {
return root;
}
}
public static void main(String [] args) {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
Node root = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.Scanner;

public class Solution {
public static void main(String [] args) {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int size = scan.nextInt();
long sum = 0; // use long to prevent integer overflow
Expand Down
Loading

0 comments on commit ba2c707

Please sign in to comment.