This file contains hidden or 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.LinkedList; | |
| import java.util.Queue; | |
| class Point{ | |
| int x; | |
| int y; | |
| int distance; | |
| Point(int x, int y, int distance){ | |
| this.x = x; |
This file contains hidden or 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 PrintBrackets{ | |
| private static void printBrackets(String w){ | |
| Stack<Integer> stack = new Stack<>(); | |
| int count = 1; | |
| for(char c : w.toCharArray()){ | |
| if(isOpeningSymbol(c)) { | |
| System.out.print(count+" "); | |
| stack.add(count++); | |
| } | |
| if(isClosingSymbol(c)) { |
This file contains hidden or 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.HashMap; | |
| public class Knapsack { | |
| private static HashMap<String, Integer> map = new HashMap<>(); | |
| private static int ks(int i, int w, int[] weight, int[] profit){ | |
| if(i < 0 || w == 0) | |
| return 0; | |
| String key = i + " -> " + w; | |
| if(map.containsKey(key)) | |
| return map.get(key); |
This file contains hidden or 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
| def coin_change(coins, amount, items, lookup): | |
| key = str(amount) + '->' + str(items) | |
| if key in lookup: | |
| return lookup[key] | |
| else: | |
| if amount == 0: | |
| lookup[key] = 1 | |
| return 1 | |
| if amount < 0 or items < 0: | |
| lookup[key] = 0 |
This file contains hidden or 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
| def print_jobs(jobs): | |
| slots = [False] * len(jobs) | |
| result = [9] * len(jobs) | |
| jobs.sort(reverse=True, key=lambda x: x[2]) | |
| d_max = max(jobs, key=lambda x: x[1])[1] | |
| count = 0 | |
| for i in range(len(jobs)): | |
| k = min(d_max, jobs[i][1]) | |
| while k >= 1: | |
| if not slots[k]: |
This file contains hidden or 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.ArrayList; | |
| import java.util.HashMap; | |
| import java.util.List; | |
| import java.util.Map; | |
| class TrieNode{ | |
| private Map<Character, TrieNode> children; | |
| private boolean wordBreak; | |
| private int count; |
This file contains hidden or 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.*; | |
| class Node{ | |
| int data; | |
| Node parent; | |
| int rank; | |
| } | |
| public class DisjointSet{ | |
| private Map<Integer, Node> map; |
This file contains hidden or 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 trees; | |
| import java.util.Arrays; | |
| class AVL { | |
| private class Node{ | |
| int data, height; | |
| Node left, right; | |
| Node(int data) { |
This file contains hidden or 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.*; | |
| public class BinaryTree{ | |
| static class Node{ | |
| int data; | |
| Node left, right; | |
| Node(int data){ | |
| this.data = data; | |
| left = right = null; |
This file contains hidden or 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 string; | |
| public class Manacher { | |
| private static char[] preprocess(String s){ | |
| char[] t = new char[s.length() * 2 + 1]; | |
| t[0] = '#'; | |
| for(int i=0; i<s.length(); i++){ | |
| t[2 * i + 1] = s.charAt(i); | |
| t[2 * i + 2] = '#'; | |
| } |