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
| 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
| 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
| 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
| 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
| 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.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
| n = (int(input('Enter number of queens\n'))) | |
| board = [[0] * n for i in range(n)] | |
| def is_safe(row, col): | |
| for i in range(n): | |
| if board[row][i] == 1 or board[i][col] == 1: | |
| return False | |
| for i in range(n): | |
| for j in range(n): |
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
| __author__ = 'Ankit Sharma' | |
| class Stack: | |
| """ This is an easy implementation of a stack """ | |
| def __init__(self): | |
| self.stack = [] | |
| def push(self, some_value): |
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
| #include "stdio.h" | |
| #include "stdlib.h" | |
| #define pf printf | |
| #define sf scanf | |
| typedef struct tree | |
| { | |
| int data; | |
| struct tree *left,*right; | |
| }node,*nodeptr; | |
| nodeptr tree=NULL; |