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 MinStack { | |
| private static class Node { | |
| private int data; | |
| private int min; | |
| private Node next; | |
| Node(int data) { | |
| this.data = data; | |
| this.min = data; | |
| this.next = 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
| import org.springframework.web.multipart.MultipartFile; | |
| import java.io.File; | |
| import java.io.IOException; | |
| import java.nio.file.Files; | |
| import java.nio.file.Path; | |
| import java.nio.file.Paths; | |
| import java.nio.file.StandardCopyOption; | |
| import java.util.Arrays; | |
| import java.util.Calendar; |
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
| class SuffixArray: | |
| def __init__(self, s): | |
| self.sa = self.build_sa(s) | |
| self.lcp = self.build_lcp(s, self.sa) | |
| @staticmethod | |
| def count_sort(k, sa, ra): | |
| n = len(sa) | |
| N = n + 256 | |
| nsa = [i for i in sa] |
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 GFG{ | |
| private static List<Integer> getFactors(int n){ | |
| List<Integer> list = new ArrayList<>(); | |
| list.add(1); list.add(n); | |
| for(int i=2; i*i <= n; i++){ | |
| if(n % i == 0) list.add(i); | |
| if(i*i != n) list.add(n / i); | |
| } |
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.io.*; | |
| class GFG{ | |
| private static int getDigits(int n){ | |
| return (int)(Math.log10(n)) + 1; | |
| } | |
| private static int getFirst(int n){ | |
| int digits = getDigits(n); | |
| return n / ((int)Math.pow(10, digits-1)); | |
| } |
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 SegmentTree { | |
| private int[] tree; | |
| private int n; | |
| SegmentTree(int[] a) { | |
| int n = a.length; | |
| tree = new int[n << 1]; | |
| construct(a); | |
| } |
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 strings; | |
| public class KMP { | |
| private static int[] buildLPS(String pattern){ | |
| int[] lps = new int[pattern.length()]; | |
| int j = 0; | |
| int i = 1; | |
| while(i < pattern.length()){ | |
| if(pattern.charAt(j) == pattern.charAt(i)){ |
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] = '#'; | |
| } |
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 trees; | |
| import java.util.Arrays; | |
| class AVL { | |
| private class Node{ | |
| int data, height; | |
| Node left, right; | |
| Node(int data) { |
NewerOlder