Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Madhur Ahuja madhur

🎯
Focusing
Block or report user

Report or block madhur

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View ipmatching.java
// java.util.* and java.util.streams.* have been imported for this problem.
// You don't need any other imports.
public static ArrayList<String> generateIPAddrs(String s) {
Stack<IpLevelNode> st = new Stack<>();
ArrayList<String> answer = new ArrayList<>();
Character c = s.charAt(0);
Integer numValue = Character.getNumericValue(c);
View mergeintervals.java
public static ArrayList<Interval> insertRange(ArrayList<Interval> intervalsList, Interval insert) {
ArrayList<Interval> out = new ArrayList<>();
for(Interval i: intervalsList){
if(i.end < insert.start) {
out.add(i);
}
else if(i.start > insert.end) {
out.add(insert);
insert = i;
}
View maximummatrixsumdfs.java
// java.util.* and java.util.streams.* have been imported for this problem.
// You don't need any other imports.
public static int matrixMaxSumDfs(int[][] grid) {
int[] sum = new int[1];
int answer = helper(grid, 0, 0, sum);
return answer;
}
@madhur
madhur / deletebstnode.java
Created May 29, 2019
Delete node from bst
View deletebstnode.java
public TreeNode delete(TreeNode root, int data) {
if(root == null) {
return null;
} else if(data < root.data) {
root.left = delete(root.left, data);
} else if(data > root.data) {
root.right = delete(root.right, data);
} else { //element found
if(root.left != null && root.right != null) { //full node case
root.data = findMin(root.right).data;
@madhur
madhur / longestnrsubstring.java
Created May 27, 2019
Longest non repeating substring
View longestnrsubstring.java
public static int longestNRSubstringLen(String input) {
if(input==null)
return 0;
char[] array = input.toCharArray();
int prev = 0;
HashMap<Character, Integer> characterMap = new HashMap<Character, Integer>();
for (int i = 0; i < array.length; i++) {
if (!characterMap.containsKey(array[i])) {
View addlinkedlist.java
public static ListNode sumTwoLinkedLists(ListNode input1, ListNode input2) {
int carryComponent =0;
ListNode returnHead = new ListNode(0);
ListNode n1 = input1, n2 = input2, n3=returnHead;
while(n1 != null || n2 != null){
if(n1 != null){
carryComponent += n1.data;
n1 = n1.next;
@madhur
madhur / mindepthtree.java
Created May 26, 2019
Minmum depth of a tree
View mindepthtree.java
// java.util.* and java.util.streams.* have been imported for this problem.
// You don't need any other imports.
public int minTreeDepth(TreeNode root) {
if (root == null) {
return 0;
}
Queue<TreeNode> currQ = new LinkedList<TreeNode>();
@madhur
madhur / reverselist.java
Created May 25, 2019
Reverse linked list
View reverselist.java
public ListNode reverseList(ListNode head) {
// Add your code below this line. Do not modify any other code.
ListNode currentNode = head;
ListNode previousNode= null;
while(currentNode != null)
{
ListNode nextNode = currentNode.next;
currentNode.next = previousNode;
@madhur
madhur / leveltraversal.java
Created May 25, 2019
Level order traversal
View leveltraversal.java
public ArrayList<Integer> levelorder(TreeNode root) {
ArrayList<Integer> levelOrderedList = new ArrayList<Integer>();
Queue<TreeNode> q = new LinkedList<TreeNode>();
TreeNode curr = null;
if(root == null) {
return null;
}
q.add(root);
while(!q.isEmpty()) {
curr = (TreeNode)q.remove();
@madhur
madhur / matrixpaths.java
Created May 25, 2019
Print matrix paths
View matrixpaths.java
// java.util.* and java.util.streams.* have been imported for this problem.
// You don't need any other imports.
public ArrayList<String> printPaths(char[][] board){
StringBuilder sb = new StringBuilder();
ArrayList<String> paths = new ArrayList<String>();
if(board.length ==0 || board[0].length==0) return paths;
You can’t perform that action at this time.