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.interview.string; | |
/** | |
* Date 09/25/2014 | |
* @author Tushar Roy | |
* | |
* Rabin Karp algorith for substring matching. | |
* | |
* Time complexity in worst case O(n^2)(depends on hash function) | |
* Space complexity O(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
#include <bits/stdc++.h> | |
using namespace std; | |
string stradd(string s1, string s2) | |
{ | |
int i; | |
string a; | |
if(s2.size() < s1.size()) | |
{ | |
swap(s1, s2); |
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
/** | |
* Algorithm to generate all possible combinations of 0s & 1s, for any length of digits | |
* author Ion Dodon | |
*/ | |
#include <iostream> | |
using namespace std; | |
int length; |
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 <bits/stdc++.h> | |
#define MEM(a,b) memset((a),(b),sizeof(a)) | |
#define MAX(a,b) ((a)>(b)?(a):(b)) | |
#define MIN(a,b) ((a)<(b)?(a):(b)) | |
#define MIN3(a,b,c) MIN(MIN(a,b),c) | |
#define MIN4(a,b,c,d) MIN(MIN(MIN(a,b),c),d) | |
#define In freopen("In.txt", "r", stdin); | |
#define Out freopen("out.txt", "w", stdout); |
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 <bits/stdc++.h> | |
using namespace std; | |
int main() | |
{ | |
int n; | |
cin >> n; | |
if(n%2) | |
cout << n << " is an odd number" << endl; |
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
/** | |
* Generate all combination of size k and less of adjacent numbers | |
* e.g 1,2,3,4 k = 2 | |
* 1 2 3 4 | |
* 12 3 4 | |
* 1 23 4 | |
* 1 2 3 34 | |
* 12 34 | |
* @author tusroy | |
* |
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
import java.util.HashMap; | |
import java.util.Map; | |
/** | |
* Date 03/21/2016 | |
* @author Tushar Roy | |
* | |
* Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. | |
* | |
* Time complexity O(n^2) |
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
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Comparator; | |
import java.util.List; | |
/** | |
* http://www.geeksforgeeks.org/closest-pair-of-points-onlogn-implementation/ | |
* https://www.youtube.com/watch?v=_pSl90jq-m0 another good explanation | |
* Given coordinates of points find closest pair points distance. | |
* |
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
import java.util.*; | |
/** | |
* Date 01/07/2016 | |
* @author Tushar Roy | |
* | |
* Given skyline of a city merge the buildings | |
* | |
* Time complexity is O(nlogn) | |
* Space complexity is O(n) |
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.interview.graph; | |
import java.util.*; | |
/** | |
* Date 04/14/2014 | |
* @author Tushar Roy | |
* | |
* Ford fulkerson method Edmonds Karp algorithm for finding max flow | |
* |