Skip to content

Instantly share code, notes, and snippets.

import javafx.util.Pair;
import java.util.HashSet;
import java.util.Set;
interface Robot {
boolean move();
void turnLeft();
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 {
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 "";
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);