This file contains hidden or 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.company; | |
import java.util.*; | |
class Interval { | |
public int start; | |
public int end; | |
public Interval(int _start, int _end) { | |
start = _start; |
This file contains hidden or 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
// https://www.youtube.com/watch?v=gm8DUJJhmY4 | |
// Binary tree traversal: Preorder, Inorder, Postorder | |
1. Visit root | |
2. Visit left sub tree | |
3. Visit right sub tree | |
struct Node { | |
char data; | |
Node *left; | |
Node *right; |
This file contains hidden or 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
// https://www.youtube.com/watch?v=86g8jAQug04 | |
#include <iostream> | |
#include <queue> | |
using namespace std; | |
struct Node | |
{ | |
char data; | |
Node *left; | |
Node *right; | |
} void LevelOrder(Node *root) |
This file contains hidden or 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
struct Node | |
{ | |
int data; | |
Node *left; | |
Node *right; | |
} | |
bool IsSubtreeLesser(Node *root, int value) | |
{ | |
if(root == NULL) return true; |
This file contains hidden or 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
// https://www.youtube.com/watch?v=gcULXE7ViZw | |
#include <iostream> | |
using namespace std; | |
struct Node | |
{ | |
int data; | |
Node *right; | |
Node *left; | |
} |
This file contains hidden or 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
// find nth fibonacci both recursive and iterative | |
// 0 1 1 2 3 5 8 13 21 | |
// 0 1 2 3 4 5 6 7 8 | |
function fibo(nth) { | |
if (nth === 0) { | |
return 0; | |
} | |
if (nth === 1) { | |
return 1; |
This file contains hidden or 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
// find nth fibonacci both recursive and iterative | |
// 0 1 1 2 3 5 8 13 21 | |
// 0 1 2 3 4 5 6 7 8 | |
function fibo(nth) { | |
// return statement | |
if (nth === 0) { | |
return 0; | |
} | |
if (nth === 1) { |
This file contains hidden or 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
// number edges in longest path | |
// depth and height are different properties | |
struct Node | |
{ | |
int data; | |
struct Node *left; | |
struct Node *right; | |
} | |
int FindHeight(struct Node *root) |
This file contains hidden or 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
// * Find max connected component in an image | |
// https://www.geeksforgeeks.org/find-number-of-islands/ | |
// https://www.geeksforgeeks.org/find-the-number-of-islands-set-2-using-disjoint-set/ | |
// https://leetcode.com/problems/number-of-islands/description/ | |
// https://leetcode.com/problems/number-of-islands/discuss/131474/Clean-javascript-solution-using-DFS | |
// https://leetcode.com/problems/number-of-islands/discuss/131165/Detailed-Explanation-of-the-Java-solution | |
var input = [ | |
[1, 1, 1, 1, 0], | |
[1, 1, 0, 1, 0], | |
[1, 1, 0, 0, 0], |
This file contains hidden or 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
struct BstNode | |
{ | |
int data; | |
BstNode *left; | |
BstNode *right; | |
}; | |
int FindMin(BstNode *root) | |
{ | |
if (root == NULL) |
OlderNewer