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
// http://www.geeksforgeeks.org/connect-nodes-at-same-level/ | |
void foo(t){ | |
if(!t) return; | |
it(t -> left != NULL){ | |
if(t->right != NULL){ | |
t -> left -> next = t -> right; | |
} | |
else { | |
if(t->next->left != NULL){ |
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 the longest arithematic progression in an array using DP Method | |
* Reference:- geeksforgeeks | |
* Author: Rohith | |
*/ | |
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
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
#include <iostream> | |
#include <string> | |
#include <cstring> | |
#include <vector> | |
#include <cmath> | |
using namespace std; | |
int n,k; | |
vector<char> str(35); |
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
#include <iostream> | |
#include <cstring> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
class Fragile2{ | |
public: | |
int isSafe(vector<vector<int> > &M, int row, int col, vector<vector<bool> > &visited){ |
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
class Solution { | |
public: | |
int majorityElement(vector<int> &num) { | |
int cnt = 0; | |
for(int i=0; i<num.size(); i++){ | |
if(cnt == 0){ | |
maj = num[i]; | |
cnt++; | |
} | |
else if(maj == num[i]) |
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
This consists of common interview questions i need to see before i go for an interview:- | |
1) https://github.com/sagivo/algorithms | |
2) http://www.ardendertat.com |
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
/* | |
1) using two queues | |
2) using cnt method | |
3) using height method | |
*/ | |
//using two queues method | |
class Solution { | |
public: | |
vector<vector<int> > levelOrder(TreeNode *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
/* | |
Using morris algorithm | |
Just traverse the tree and whenerv u find that there are two elements that values neeeds are not in order, | |
just store them as first and second and swap them. | |
*/ | |
TreeNode *first = NULL; | |
TreeNode *second = NULL; | |
TreeNode *previous = NULL; | |
void recoverTree(TreeNode *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
/* | |
Amazing algorithm:- | |
inorder traversal without using stacks and recursion just by manipulating threads between them. | |
http://www.geeksforgeeks.org/inorder-tree-traversal-without-recursion-and-without-stack/ | |
*/ | |
void inorder_morris(node *root){ | |
if(root == NULL) return ; | |
node *cur, *pre; | |
cur = 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
// A divide and conquer program in C/C++ to find the smallest distance from a | |
// given set of points. | |
#include <stdio.h> | |
#include <float.h> | |
#include <stdlib.h> | |
#include <math.h> | |
// A structure to represent a Point in 2D plane | |
struct Point |