Skip to content

Instantly share code, notes, and snippets.

View rohith2506's full-sized avatar

Rohith Uppala rohith2506

View GitHub Profile
/*
Simple logic.
if char is '(': store that locations in stack. push 0 into vec ( for storing the longest parantheses value until there in vec )
else:
if it is not empty: valid parantheses, take the location from stack. calculate length. update it via the value stored in vec. update max
else: just push 0 into vec ( for storing longest parantheses length until there )
return total_max
*/
/*
O(n) solution using BFS.
Let's say we have [2,3,1,1,4]. Divide values into nodes such that nodes at level i can be reached by jump from level (i-1)
now didiving into levels, [2 || 3,1 || 1,4]
*/
class Solution {
public:
/*
Solution still not complete.
*/
class Solution{
public:
void dfs(vector<vector<int> > paths, vector<string> words, vector<string> v, string start, string end){
if(start == end){
result.push_back(v);
return ;
/*
For ref:
https://oj.leetcode.com/discuss/12780/my-concise-c-solution-ac-90-ms
This is the classic problem.
1) Know how to solve largest rectangle in histogram.
Solution:-
for every index i {
for every index j less than its height{
calculate height * (distance between this rectangle and that rectangle)
'''
Only trciky part is dictioanry mod.
How did he do it??
let's say 0.147851...
First when 1 encouters mod[1] = 0(index) will be stored
now when again 1 encounters, it's already present
so first for loop is from (0 to 0)
and second for loop is from (1 to 5)(5 is the index where it again occured)
and return the solution
// 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
/*
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;
@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) {
/*
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 / 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