Skip to content

Instantly share code, notes, and snippets.

View madhur's full-sized avatar
🎯
Focusing

Madhur Ahuja madhur

🎯
Focusing
View GitHub Profile
@madhur
madhur / leveltraversal.java
Created May 25, 2019 15:11
Level order traversal
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 15:05
Print matrix paths
// 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;
@madhur
madhur / pathlengthfromroot.java
Created May 25, 2019 13:05
Path length from root
public int pathLengthFromRoot(TreeNode root, int n1) {
if (root == null) return 0;
else {
int out = 0;
if ((root.data == n1) || (out = pathLengthFromRoot(root.left, n1)) > 0
|| (out = pathLengthFromRoot(root.right, n1)) > 0) {
return out + 1;
}
return 0;
}
@madhur
madhur / printbylevel.java
Created May 25, 2019 12:55
Print a Binary Tree Level by Level
// java.util.* and java.util.streams.* have been imported for this problem.
// You don't need any other imports.
public ArrayList<ArrayList<Integer>> printLevelByLevel(TreeNode root) {
ArrayList<Integer> nodeList = new ArrayList<Integer>();
ArrayList<Integer> levelList = new ArrayList<Integer>();
ArrayList<ArrayList<Integer>> myList = new ArrayList<ArrayList<Integer>>();
@madhur
madhur / serialize.java
Created May 25, 2019 09:05
Binary tree serialization and de-serialization
public String serializeTree(TreeNode root){
StringBuilder sb = new StringBuilder();
serializeTreeHelper(root,sb);
if(sb.length() > 0) sb.deleteCharAt(0);
return sb.toString();
}
private StringBuilder serializeTreeHelper(TreeNode t, StringBuilder sb){
if(t == null) sb.append(",null");
else {
@madhur
madhur / calibretheme.css
Created November 28, 2018 02:36
My calibre theme
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
nav,
section,
import java.util.*;
public class Problem3 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int testCases = scan.nextInt();
List<Integer> numbers = new ArrayList<>();
for ( int i =1; i<=testCases; ++i) {
@madhur
madhur / delta.java
Created October 26, 2017 11:17
DeltaEncoding
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String args[] ) throws Exception {
Scanner scan = new Scanner(System.in);
@madhur
madhur / test.java
Created August 15, 2017 14:16
test.java
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Created by madhur on 15 Aug.
*/
public class IntegerArrayFlattener {
@madhur
madhur / cloudSettings
Last active August 16, 2020 07:45
Visual Studio Code Sync Settings Gist
{"lastUpload":"2020-08-16T07:45:51.198Z","extensionVersion":"v3.4.3"}