Skip to content

Instantly share code, notes, and snippets.

View rohith2506's full-sized avatar

Rohith Uppala rohith2506

View GitHub Profile
@rohith2506
rohith2506 / 1.cpp
Created February 26, 2015 10:25
Connect Nodes at same level -- (Amazon)
// 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){
@rohith2506
rohith2506 / llap.cpp
Created February 20, 2015 09:59
Longest Arithmetic progression in an array [UNSOLVED]
/*
* Find the longest arithematic progression in an array using DP Method
* Reference:- geeksforgeeks
* Author: Rohith
*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
using namespace std;
int n,k;
vector<char> str(35);
#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){
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])
@rohith2506
rohith2506 / gist:f4aceb9a0317c9c0054d
Last active August 29, 2015 14:12
Core Algo list to follow before any interview.
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
/*
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) {
@rohith2506
rohith2506 / recover_binary_tree.cpp
Created December 26, 2014 06:53
Recover Binary tree without in constant space when two elements are accidentally swapped
/*
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) {
/*
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;
// 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