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)){ |
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
/** | |
* Definition for an interval. public class Interval { int start; int end; | |
* Interval() { start = 0; end = 0; } Interval(int s, int e) { start = s; end = | |
* e; } } | |
*/ | |
class MergeIntervals { | |
public List<Interval> merge(List<Interval> intervals) { | |
if (intervals.size() < 0) { | |
return null; |
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
public class UniquePath { | |
public int uniquePaths(int m, int n) { | |
// add more comments | |
if (m == 0 || n == 0) { | |
return 0; | |
} | |
int[][] dp = new int[m][n]; | |
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.List; | |
public class MaximumSumOfTriangularSeries { | |
public static void main(String[] args) { | |
List<List<Integer>> triangle = new ArrayList<List<Integer>>(); | |
ArrayList<Integer> test = new ArrayList<Integer>(); | |
test.add(2); |
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.interview.dynamic; | |
public class WildCardMatching { | |
public boolean isMatch(String s, String p) { | |
char[] str = s.toCharArray(); | |
char[] pattern = p.toCharArray(); | |
//replace multiple * with one * | |
//e.g a**b***c --> a*b*c | |
int writeIndex = 0; | |
boolean isFirst = true; |
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.guess.output; | |
public class ChangeObjectReferenceInsideMethod { | |
public class A { | |
int attr; | |
public void setAttr(int a) { | |
this.attr = a; | |
} | |
} |
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 numIslands(char[][] grid) { | |
int count =0; | |
if (grid.length == 0){ | |
return 0; | |
} | |
boolean [][] visited = new boolean[grid.length][grid[0].length]; | |
for (int i =0; i < grid.length; i++){ | |
for (int j = 0 ; j < grid[0].length; j++){ | |
if (grid[i][j]=='1' && !visited[i][j]){ |
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
/** | |
* Constructs a new, empty tree set, sorted according to the specified | |
* comparator. All elements inserted into the set must be <i>mutually | |
* comparable</i> by the specified comparator: {@code comparator.compare(e1, | |
* e2)} must not throw a {@code ClassCastException} for any elements | |
* {@code e1} and {@code e2} in the set. If the user attempts to add | |
* an element to the set that violates this constraint, the | |
* {@code add} call will throw a {@code ClassCastException}. | |
* | |
* @param comparator the comparator that will be used to order this set. |
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.ge.current.points; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.Comparator; | |
import java.util.TreeMap; | |
import java.util.TreeSet; | |
public class SortData { | |
public static void main(String[] args) { |