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
package com.abhishek.dojo; | |
import java.util.Arrays; | |
// http://buttercola.blogspot.com/2015/09/leetcode-walls-and-gates.html | |
public class WallsAndGates { | |
public static void main(String[] args) { | |
int[][] grid = new int[][] { | |
{2147483647, -1, 0, 2147483647}, |
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
package com.abhishek.dojo; | |
import java.util.HashSet; | |
import java.util.LinkedList; | |
import java.util.Queue; | |
public class MinimumMutationGene { | |
public static void main(String[] args) { | |
minMutation("AACCGGTT", "AAACGGTA", new String[] {"AACCGGTA", "AACCGCTA", "AAACGGTA"}); |
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
package com.abhishek.dojo; | |
public class BuySellStocks { | |
public static void main(String[] args) { | |
BuySellStocks bss = new BuySellStocks(); | |
// case 1- stock price always increasing | |
// you need to buy first and sell later | |
// Lowest buy value- 10 |
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
package com.abhishek.dojo; | |
import java.util.HashSet; | |
/*Write an algorithm to determine if a number is "happy". | |
A happy number is a number defined by the following process: | |
Starting with any positive integer, replace the number by the sum of | |
the squares of its digits, and repeat the process until the number | |
equals 1 (where it will stay), or it loops endlessly in a cycle |
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
package com.abhishek.dojo; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Comparator; | |
import java.util.Optional; | |
public class LongestIncreasingSubsequence { | |
public static void main(String[] args) { |
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
package com.abhishek.dojo; | |
import java.util.ArrayList; | |
import java.util.HashMap; | |
import java.util.Map.Entry; | |
import java.util.PriorityQueue; | |
public class TopKRepeatingElements { | |
class Pair { | |
int num; |
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
package com.abhishek.dojo.arrays; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
public class MergeSortedArrays { | |
public static int[] mergeArrays(int[] firstArr, int[] secondArr) { | |
ArrayList test = new ArrayList(Arrays.asList("a", "b", "c")); | |
// combine the sorted arrays into one large sorted array |
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
package com.abhishek.dojo; | |
import java.util.HashMap; | |
import java.util.Map; | |
public class WordCloud { | |
private Map<String, Integer> wordsToCounts = new HashMap<String, Integer>(); | |
public WordCloudData(String inputString) { | |
populateWordsToCounts(inputString); |
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
import java.util.ArrayDeque; | |
import java.util.Deque; | |
public class MaxStack { | |
private Deque<Integer> stack = new ArrayDeque<>(); | |
private Deque<Integer> maxesStack = new ArrayDeque<>(); | |
// Add a new item to the top of our stack. If the item is greater | |
// than or equal to the last item in maxesStack, it's | |
// the new max! So we'll add it to maxesStack. | |
public void push(int item) { |
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 GroupAnagrams { | |
public List<List<String>> groupAnagrams(String[] strs) { | |
HashMap<String, List> map = new HashMap<String, List>(); | |
for (String word: strs){ | |
char[] chars = word.toCharArray(); | |
// sorting changes original data structure | |
Arrays.sort(chars); | |
// short for converting character array to string | |
String key = String.valueOf(chars); | |
if (!map.containsKey(key)){ |
OlderNewer