Skip to content

Instantly share code, notes, and snippets.

View arpi-r's full-sized avatar

Arpitha Raghunandan arpi-r

View GitHub Profile
@arpi-r
arpi-r / DifferentBitsSumPairwise.cpp
Created October 18, 2018 19:08
codebuddy week6
#define m 1000000007
int Solution::cntBits(vector<int> &A) {
long long count=0;
int t = 1;
for(int i = 1; i < 32 ; i++){
long long one = 0, zero = 0;
if( i==1 ){
t = 1;
}
@arpi-r
arpi-r / RainWaterTrapped.cpp
Created October 14, 2018 11:06
codebuddy week5
int max(int a, int b ){
if( a > b )
return a;
return b;
}
int min(int a, int b ){
if( a < b )
return a;
return b;
@arpi-r
arpi-r / RotatedBinarySearch.cpp
Created October 12, 2018 18:09
WebClub codebuddy week2
// Web Club Codebuddy Week 2
int BinarySearch(const vector<int> &A,int B,int l,int h) {
int m = (l+h)/2;
if(l>h)
return -1;
if(A[m] == B)
return m;
if(A[m] < B)
@arpi-r
arpi-r / generateallparenthesesII.py
Created October 6, 2018 05:26
WebClub codebuddy week1
class Solution:
# @param A : integer
# @return a list of strings
def generateParenthesis(self, A):
l=[]
if(A>=1):
l=['(']
while True:
no=nc=0
nl=[]
@arpi-r
arpi-r / 3sum.cpp
Created September 14, 2018 17:05
codebuddy week3
int Solution::threeSumClosest(vector<int> &A, int B) {
sort(A.begin(), A.end());
int sum = A[0] + A[1] + A[2];
for(int i = 0; i < A.size()-2; i++)
{
int j = i+1, k = A.size()-1;
while(j < k)
{
int s = A[i]+A[j]+A[k];
if(abs(B-s) < abs(B-sum))
@arpi-r
arpi-r / sortedpermutationrank.cpp
Created September 7, 2018 17:40
codebuddy week2
#define M 1000003
unsigned int factorial(unsigned int n)
{
if (n == 0)
return 1;
return ((n%M) * (factorial(n - 1)%M))%M;
}
int Solution::findRank(string A) {
@arpi-r
arpi-r / maxunsortedsubarray.cpp
Created August 31, 2018 18:13
codebuddy week1
vector<int> Solution::subUnsort(vector<int> &A) {
vector<int> r;
vector<int> t;
int f=0,l=A.size()-1;
int i,s=A.size();
for(i=0;i<s-1;i++){
if(A[i]>A[i+1]){
f=i;
break;
}