Skip to content

Instantly share code, notes, and snippets.

View Abhishek-Chaudhary-InfoCepts's full-sized avatar

abhishek Abhishek-Chaudhary-InfoCepts

View GitHub Profile
/**
* 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;
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)){
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) {
package com.abhishek.dojo.lru;
import java.util.Iterator;
import java.util.LinkedHashMap;
public class LRUCache {
private int capacity;
// use linkedhashmap to maintain the sequence
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);
package com.abhishek.dojo.arrays;
//reference- https://www.youtube.com/watch?v=CGMNePwovA0
public class NumberofIslandsChar {
public static void main(String[] args) {
NumberofIslandsChar n = new NumberofIslandsChar();
// expected = 3
char[][] grid = { { '1', '1', '0', '0', '0' },
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
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;
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) {
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