Skip to content

Instantly share code, notes, and snippets.

View devteampentagon's full-sized avatar

Team Pentagon devteampentagon

View GitHub Profile
@devteampentagon
devteampentagon / Rabin Karp Search Algorithms.java
Created January 12, 2017 05:59
Rabin Karp Search Algorithms
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)
@devteampentagon
devteampentagon / String Multiplication & String Addition.cpp
Created January 11, 2017 11:15
String Multiplication & String Addition
#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);
@devteampentagon
devteampentagon / Algorithm to generate all possible combinations of 0s &amp; 1s for any length of digits.cpp
Created January 11, 2017 11:13
Algorithm to generate all possible combinations of 0s &amp; 1s for any length of digits
/**
* Algorithm to generate all possible combinations of 0s & 1s, for any length of digits
* author Ion Dodon
*/
#include <iostream>
using namespace std;
int length;
@devteampentagon
devteampentagon / Area of a triangle [cordinate geometry].cpp
Created January 10, 2017 20:18
Area of a triangle [cordinate geometry]
#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);
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
if(n%2)
cout << n << " is an odd number" << endl;
@devteampentagon
devteampentagon / Generate all combination of size k and less of adjacent numbers.java
Created January 7, 2017 16:30
Generate all combination of size k and less of adjacent numbers
/**
* 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
*
@devteampentagon
devteampentagon / Maximum number of points that lie on the same straight line.java
Created January 7, 2017 16:22
Maximum number of points that lie on the same straight line
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)
@devteampentagon
devteampentagon / Closest Pair Of Points.java
Created January 7, 2017 16:19
Closest Pair Of Points
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.
*
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)
package com.interview.graph;
import java.util.*;
/**
* Date 04/14/2014
* @author Tushar Roy
*
* Ford fulkerson method Edmonds Karp algorithm for finding max flow
*