Skip to content

Instantly share code, notes, and snippets.

class Solution {
Map<String, List<String>> adjList = new HashMap<String, List<String>>();
List<String> currPath = new ArrayList<String>();
List<List<String>> shortestPaths = new ArrayList<List<String>>();
public List<List<String>> findLadders(String beginWord, String endWord, List<String> wordList) {
// copying the words into the set for efficient deletion in BFS
Set<String> copiedWordList = new HashSet<>(wordList);
// build the graph using BFS
bfs(beginWord, endWord, copiedWordList);
class Solution {
public String alienOrder(String[] words) {
//For catching Errors
if(words.length==0) return "";
//The dependencyMap and countMap data structures
Map<Character, Set<Character>> dependencyMap = new HashMap<>();
Map<Character, Integer> countMap = new HashMap<>();
//a boolean that determines whether we can build a graph or not
boolean success = buildGraph(words, dependencyMap, countMap);
if(!success) return "";
import java.util.*;
class TrieNode {
//Hash map of character to trie node
HashMap<Character, TrieNode> children = new HashMap<Character, TrieNode>();
//A string to store the possible found words for each node
String word = null;
public TrieNode() {}
}
class Solution {
import javafx.util.Pair;
import java.util.HashSet;
import java.util.Set;
interface Robot {
boolean move();
void turnLeft();
import java.util.Arrays;
import java.util.Comparator;
public class Solution {
//A method to return the number of used rooms
public int minMeetingRooms(int[][] intervals) {
//If input == null, does not process it
import java.util.*;
public class Solution {
//Takes a 2D array as the input
public int numIslands(char[][] grid) {
//If empty, returns 0
if(grid == null || grid.length == 0)
{
import java.util.*;
class Solution {
public int[] findOrder(int numCourses, int[][] prerequisites) {
//A map to model the graph
Map<Integer, List<Integer>> adjList = new HashMap<Integer,
List<Integer>>();
//To save the indegree of each node in the graph
import java.util.*;
public class LRUCache {
//double linked list class
class DLinkedNode {
int key;
int value;
DLinkedNode prev;
DLinkedNode next;
public class Main
{
private String findLongestPalindromicSubstring(String input)
{
//If empty, does not analyze the string
if(input.isEmpty())
{
return "";
}
class Solution
{
//The function checks if a substring with given start and end points
//is a palindrome or not.
public boolean isPalindrome(String s, int start, int end)
{
while (start < end)
{
if (s.charAt(start) != s.charAt(end))
return false;