Skip to content

Instantly share code, notes, and snippets.

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

abhishek Abhishek-Chaudhary-InfoCepts

View GitHub Profile
// 1. word break 1
public boolean dfs(String s, List<String> wordDict) {
return dfs(s, new HashSet<>(wordDict), 0);
}
public boolean dfs(String s, Set<String> wordDict, int start) {
if (start == s.length()) {
return true;
}
for (int end = start + 1; end <= s.length(); end++) {
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];
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.lru;
import java.util.Iterator;
import java.util.LinkedHashMap;
public class LRUCache {
private int capacity;
// use linkedhashmap to maintain the sequence
package com.dojo.java8.tutorials.hashmap;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;
public class HashMapSortingByValues {
package com.dojo.java8.tutorials.hashmap;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
public class HashMapSortingByKeys {
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) {
/**
* 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.
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]){
package com.abhishek.dojo.guess.output;
public class ChangeObjectReferenceInsideMethod {
public class A {
int attr;
public void setAttr(int a) {
this.attr = a;
}
}