Skip to content

Instantly share code, notes, and snippets.

View criskgl's full-sized avatar
👨‍💻
Coding...

criskgl

👨‍💻
Coding...
View GitHub Profile
static int mostFrequent(int arr[], int n)
{
// Insert all elements in hash
Map<Integer, Integer> hp =
new HashMap<Integer, Integer>();
for(int i = 0; i < n; i++)
{
int key = arr[i];
if(hp.containsKey(key))

Graphs

Components

  • vertex: each node of the graph
  • edges: describe realationships between vertices

Types

  • Weigthed / Not Weigthed
Map<Integer, Integer> hp = new HashMap<Integer, Integer>();
public static void main(String[] args){
//create threadpool
ExecutorService pool = Executors.newFixedThreadPool(iterations);
//create array of runnables that will be used to lunch each thread
myRunnable [] vec = new myRunnable [iterations];
//fill array of runnables
int iterations = 10;
for(int iter = 0; iter < iterations; iter++){
/*
*In an array a
*figures out the element e
*in an index after performing r RIGHT rotations
*/
public class Tragaperras {
static int circularRightArrayRotation(int[] a, int r, int index) {
int l = a.length;
int R = r - (r/l*l);
//Get rid of over-rotations
/*
*In an array a
*figures out the element e
*in an index after performing r LEFT rotations
*/
public class Tragaperras {
static int circularLeftArrayRotation(int[] a, int r, int index) {
int l = a.length;
int R = r - (r/l*l);
//Get rid of over-rotations
// Following program is a Java implementation
// of Rabin Karp Algorithm given in the CLRS book
public class Main
{
// d is the number of characters in the input alphabet
public final static int d = 256;
/* pat -> pattern
txt -> text
public class MaxSubArraySum {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] a = {1, -3, 2, 1,-1};
int result = maxSumSubarray(a);
System.out.println(result);
}
public static int maxSumSubarray(int[] A){
public class MinSubArraySum {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] a = {1, 3, -2, -1,1};
int result = minSumSubarray(a);
System.out.println(result);
}
public static int minSumSubarray(int[] A){
@criskgl
criskgl / unsortedLinkedListDeleteDups.java
Created August 17, 2019 19:49
## Delete dups unsorted linked list ### O(n) time with Buffer If we can have a data structure that keeps track of the recently visited elements we can run through the array and at each point check in O(1) times in our e.g Hashmap if the element exi
public class removeDupsUnsorted {
public static void main(String[] args){
//Create unsorted linked list
List<Integer> list = new LinkedList<Integer>();
list.add(4);
list.add(3);
list.add(1);
list.add(3);
list.add(6);