This file contains 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 Solution { | |
public String alienOrder(String[] words) { | |
int[] indegree = new int[26]; | |
Map<Character, Set<Character>> graph = buildGraph(words, indegree); | |
System.out.println(String.format("Graph %s", graph)); | |
System.out.println(String.format("Indegree %s", Arrays.toString(indegree))); | |
return topSort(graph, words, indegree); | |
} | |
private String topSort(Map<Character, Set<Character>> graph, String[] words, int[] indegree) { |
This file contains 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 Solution { | |
public int maximalSquare(char[][] matrix) { | |
if(matrix.length == 0) return 0; | |
int[][] dp = new int[matrix.length][matrix[0].length]; | |
Integer max = 0; | |
for(int i = 0;i<dp.length;i++) { | |
//initialize | |
if(matrix[i][0]=='1') { | |
max = 1; | |
dp[i][0] = 1; |
This file contains 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 Solution { | |
private boolean isPred(String a, String b) { | |
int diff = 0; | |
if(a.length() != b.length()-1) return false; | |
for(int i = 0 , j = 0;i<a.length() && j<b.length() ;) { | |
if(a.charAt(i) == b.charAt(j)) { | |
i++; | |
j++; | |
} else { |
This file contains 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 Solution { | |
public int longestStrChain(String[] words) { | |
System.out.println(isPred("bca","bda")); | |
Arrays.sort(words); | |
List<String> maxList = new ArrayList<>(); | |
Map<String, List<String>> map; | |
Graph<String> graph = new Graph(); | |
for(int i = 0;i<words.length;i++) { | |
for(int j = i+1;j<words.length;j++) { | |
if(words[i].length()!=words[j].length()-1) break; |
This file contains 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 Solution { | |
public String reorganizeString(String S) { | |
Character[] c = new Character[S.length()]; | |
Map<Character, Integer> map = new HashMap<>(); | |
for(int i = 0;i<S.length();i++) { | |
c[i] = S.charAt(i); | |
map.putIfAbsent(S.charAt(i), 0); | |
map.put(S.charAt(i), map.get(S.charAt(i))+1); | |
} | |
Arrays.sort(c, new Comparator<Character>(){ |
This file contains 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 Solution { | |
public boolean areSentencesSimilarTwo(String[] words1, String[] words2, List<List<String>> pairs) { | |
if(words1.length != words2.length) return false; | |
Graph<String> graph = new Graph(); | |
for(List<String> list: pairs) { | |
String key = list.get(0); | |
String value = list.get(1); | |
if(!key.equals(value)) { | |
graph.addNode(key); | |
graph.addNode(value); |
This file contains 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 Solution { | |
public int[] assignBikes(int[][] workers, int[][] bikes) { | |
Node[] res = new Node[workers.length]; | |
Set<Integer> bikeSet = new HashSet<>(); | |
Set<Integer> workerSet = new HashSet<>(); | |
//create a heap as per condition described in the question. | |
Queue<Node> pq = new PriorityQueue<>(new Comparator<Node>(){ | |
public int compare(Node n1, Node n2) { |
This file contains 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 Solution { | |
public int[] assignBikes(int[][] workers, int[][] bikes) { | |
Node[] res = new Node[workers.length]; | |
Set<Integer> bikeSet = new HashSet<>(); | |
Set<Integer> workerSet = new HashSet<>(); | |
//create a heap as per condition described in the question. | |
Queue<Node> pq = new PriorityQueue<>(new Comparator<Node>(){ | |
public int compare(Node n1, Node n2) { |
This file contains 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 Solution { | |
private static Map<String, Set<String>> map = new LinkedHashMap<>(); | |
private static Map<String, String> temp = new HashMap<>(); | |
public boolean areSentencesSimilarTwo(String[] words1, String[] words2, List<List<String>> pairs) { | |
if(words1.length != words2.length) return false; | |
populate(pairs); | |
transformMap(); | |
This file contains 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
Verifying my Blockstack ID is secured with the address 13ENJogMTYn2xrd57VU71fTvMuBwuurfxJ https://explorer.blockstack.org/address/13ENJogMTYn2xrd57VU71fTvMuBwuurfxJ |
NewerOlder