This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DynamicFibonacci { | |
int[] fibs; | |
public static void printFibsUpToN(int n) | |
{ | |
fibs[n] = new int[n + 1] | |
} | |
public int fib(int n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void permutation(String str) | |
{ | |
permutation(str, ""); | |
} | |
public static permutation(String str, String prefix) | |
{ | |
if(str.length() == 0) | |
System.out.println(prefix); | |
else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int factorial(int n) | |
{ | |
if(n <= 1) | |
return 1; | |
else | |
return n * factorial(n - 1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static boolean isPrime(int n) | |
{ | |
for(int i = 0; i * i <= n; i++) | |
if(n % i == 0) | |
return false; | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void printUnorderedPairs(int[] array) { | |
for(int i = 0; i < array.length - 1; i++) | |
for(int j = i + i; j < array.length; j++) | |
System.out.println("(" + array[i] + ", " + array[j] + ")"); | |
} | |
/* | |
Note that 1 + 2 + 3 + 4 + 5 + ..+ n = (n * (n + 1)) / 2 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Computers m binary searches | |
public static boolean containsElements(int[] seaches, int[] array) | |
{ | |
boolean hasElements = true; | |
int m = searches.length; | |
int n = array.length; | |
// O(m) loop | |
for(int i = 0; i < m; i++) { | |
// Each Binary Search has O(lg n) complexity | |
if(binarySearch(array, searches[i] == false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Sums from 1 to n and then from 1 to m^2 | |
public static long example1(int n, int m) | |
{ | |
long sum = 0; | |
//O(n) | |
for(int i = 1; i <= n; i++;) { | |
sum += i; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void loopThroughAlphabet(int n) | |
{ | |
for(int i = 0; i < n; i++) { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package WeekOfCode.Week28; | |
import java.io.BufferedWriter; | |
import java.io.FileWriter; | |
import java.io.IOException; | |
import java.text.DecimalFormat; | |
import java.util.Scanner; | |
import java.util.TreeMap; | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.Comparator; | |
import java.util.PriorityQueue; | |
import java.util.Scanner; | |
/** | |
* Algorithms -> Sorting -> Fraudulent Activity Notifications | |
* Medium | |
*/ | |
public class FraudulentActivityNotifications { |