harshit.knit
BAN USER 0of 0 votes
Answer**Game of Bits**
 harshit.knit in India
Yale and Xavier are playing a game with numbers. Each round of the game starts with a number given to them by Zita, Yale’s little sister.
The number n is expressed as a binary integer with p bits
For every round, Xavier gets the first move.
The game came consists of moves performed by Yale and Xavier alternately.
The mth move of the game involves performing these operations on the number:
Toggling the mth bit (numbering of bits starts from left) of the number.
Toggling the left adjacent bit of m (if such a bit exists) if it is equal to the mth bit before toggling in step 1; otherwise keep it as is.
Toggling the right adjacent bit of m (if such a bit exists) if it is equal to the mth bit before toggling in step 1; otherwise keep it as is.
This modification of the number goes on until all p moves are made. If the modified number (as a result of all the operations) is
equal (or a distance one away) from the original number, then the person who made the last move wins the round; otherwise the other one wins the round.
**Note:**
The number given to them is converted to its binary form and represented with the help of minimum number of bits.
The numbering for the bits starts from the leftmost bit.
**Constraints**
1<=r<=10^6
1<=n<=10^6, where n is the number given by Zita in any round
**Input Format**
The first line contains a number, r, denoting the number of rounds in the game.
This is followed by r lines, where the ith line contains the number given by Zita for the ith round.
**Output Format**
The output of the problem has r lines, where the ith line contains the winner of ith round as X if Xavier wins ith round or Y if Yale wins the ith round.
**Sample Input**
1
11
**Sample Output**
Y
**Explanation**
11 is represented as 1011 using minimum number of bits in binary.
When Xavier makes the first move, it becomes 0011.
Then Yale makes the 2nd move and it becomes 1111.
After the third move made by Xavier, it becomes 1000.
After the last move by Yale, it becomes 1011 which is 11 in decimal.
The last move was made Yale and the modified number is equal or adjacent to 11,
therefore, Yale wins this round. Report Duplicate  Flag  PURGE
ThoughtWorks Software Engineer / Developer Algorithm  0of 0 votes
AnswersYou are given the toplogical information of a terrain in the following format  There are n points ( x_i , y_i ) and for each point (x_i , y_i ) the altitude h_i is given.
 harshit.knit in United States
For any rectangle (axis parallel) defined by the xy coordinates of
the corner points, we must answer the query about which is the highest altitude point lying within the rectangle.
Implement this using a rangequery datastructure that answers such a
query in O( log^2 n) time Report Duplicate  Flag  PURGE
Google Applications Developer Algorithm  1of 1 vote
AnswerFind Maximum sum subarray such that no elemnt in subarray is repeated
 harshit.knit in United States
https://www.facebook.com/photo.php?fbid=10152820917104183&set=pcb.1523587287892659&type=1&theater Report Duplicate  Flag  PURGE
Medio Systems Applications Developer Algorithm  0of 0 votes
AnswersWe have two strings A and B with the same super set of characters. We need to change these strings to obtain two equal strings. In each move we can perform one of the following operations:
 harshit.knit in India
1. swap two consecutive characters of a string
2. swap the first and the last characters of a string
A move can be performed on either string.
What is the minimum number of moves that we need in order to obtain two equal strings? Report Duplicate  Flag  PURGE
Trilogy Software Engineer / Developer Algorithm
#include <iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
int n;
cin>>n;
cin.ignore();
for(int i=0;i<n;i++)
{
string p,t;
getline(cin,p);
getline(cin,t);
int lp=p.length();
int lt=t.length();
int fp[26]={0},ft[26]={0};
for(int i=0;i<lp;i++)
fp[p[i]'a']++;
for(int i=0;i<lp;i++)
ft[t[i]'a']++;
bool m;
for(int i=lp;i<=lt;i++)
{
m=true;
for(int j=0;j<26;j++)
if(fp[j]!=ft[j])
{
m=false;
break;
}
if(m)
break;
ft[t[ilp]'a'];
ft[t[i]'a']++;
}
if(m)
cout<<"YES\n";
else
cout<<"NO\n";
}
return 0;
}

harshit.knit
November 05, 2014 # your code goes here
a=[]
n=int(raw_input())
for i in xrange(n):
a.append(map(int, raw_input().split(' ')))
l=[[(0,1) for x in xrange(len(a))] for x in xrange(len(a)1)]
l.append([(x,1) for x in a[len(a)1] ])
for i in reversed(xrange(len(l)1)):
for j in reversed(xrange(len(a[i]))):
l[i][j]=(a[i][j]+max(l[i+1][j][0],l[i+1][j+1][0]) ,(j if l[i+1][j][0]>l[i+1][j+1][0] else j+1))
print l
i=0
j=0
while i<len(a):
print a[i][j]," ",;
j=l[i][j][1]
i+=1

harshit.knit
November 05, 2014 a=[(int(x),1) for x in raw_input().split(' ')]
b=[(int(x),1) for x in raw_input().split(' ')]
a.extend(b)
a.sort()
c=0;
m=0
for i in a:
c+=i[1]
m=max(m,c);
print m

harshit.knit
November 04, 2014 s=raw_input()
l=[]
n=1
c=s[0]
for i in s[1:]:
if i != c:
l.append(c)
l.append(str(n))
c=i;
n=0
n+=1
print l
l.append(c)
l.append(str(n))
print "".join(l)

harshit.knit
November 04, 2014 # your code goes here
a=[int(x) for x in raw_input().split(' ')]
l=[None]
s=[a[0]]
for i in range(1,len(a)):
while len(s)>0 and s[len(s)1]>=a[i]:
s.pop()
if len(s)>0:
l.append(s[len(s)1])
else:
l.append(None);
s.append(a[i])
print l

harshit.knit
November 04, 2014 s=(raw_input())
k=int(raw_input())
def isalpha(c):
if ('A'<=c and c<='Z') or ('a'<=c and c<='z'):
return True;
else:
return False;
out=''
c=''
n=''
i=0
while i<=len(s):
if(k<=0):
out= c
break;
if isalpha(s[i]):
if len(n)>0:
k=int(n)
n=''
else:
k=1
c=s[i]
else:
n+=s[i]
i+=1;
if out=='':
print "None"
else:
print out

harshit.knit
November 04, 2014 #include <iostream>
#include<cstring>
using namespace std;
int length,start;
int cmp(char *big,char *small,int st,int len)
{
if(*small=='\0')
{
if(lenst<length)
{
length=lenst;
start=st;
}
return length;
}
else if(*big=='\0'  *big==' ')
return 1000000007;
else if(*big==*small)
{
if( st==1)
return min(cmp(big+1,small+1,len,len+1),cmp(big+1,small,st,len+1));
else
return cmp(big+1,small+1,st,len+1);
}
return cmp(big+1,small,st,len+1);
}
int main() {
char *big="hello what are you doing";
char *small="eo";
start=1;
length=strlen(big);
cout<<"length "<<cmp(big,small,1,0)<<endl;
cout<<"start from "<<start<<endl;
for(int i=start;istart<length;i++)
putchar(big[i]);
return 0;
}

harshit.knit
November 03, 2014 num=[float(x) for x in raw_input().split(' ')]
a=[x for x in num if 0< x < 1]
b=[x for x in num if 1<= x < 2]
a.sort()
min3a=a[:3]
max3a=a[len(a)3:]
if len(a)>=3:
if 2<=sum(min3a):
print None
elif 1 < sum(min3a) < 2:
print min3a
if 1<sum(max3a):
for i in range(0,4):
if 1<sum(min3a[:i]+max[i:])<2:
print min3a[:i]+max[i:]
if len(b)>=1 and len(a)>=2:
if 1<sum(min3a[0:2]+[min(b)])<2:
print min3a[0:2]+[min(b)]

harshit.knit
November 01, 2014 a=[int(x) for x in raw_input().split(' ')]
c=0;
e=None
for i in a:
if c==0:
e=i;
c=1
elif e==i:
c+=1;
elif e!=i:
c=1;
c=0;
for i in a:
if i==e:
c+=1
if c>=(len(a)+1)/2:
print e
else:
print None

harshit.knit
November 01, 2014 a=[int(x) for x in raw_input().split(' ')]
k=int(raw_input())
a=[x%k for x in a]
a.sort()
print a
j=len(a)1
i=0
c=0;
while a[i]==0:
c+=1;
i+=1;
c=c/2;
while i<j:
if a[i]+a[j]==k:
c+=2;
i+=1;
j=1;
elif a[i]+a[j]<k:
i+=1;
elif a[i]+a[j]>k:
j=1;
print "pairs",c/2

harshit.knit
November 01, 2014 n=int(raw_input())
o=int(raw_input())
dp=[[False for x in range(0,10**n)] for x in range(0,o+1)]
dp[1][1:10]=[True for x in range(1,10)]
a=[[[]for x in range(0,10**n)] for x in range(0,o+1)]
a[1][1:10]=[[x] for x in range(1,10)]
m=1;
for i in range(2,o+1):
for j in range(1,10**n):
for k in range(2,10):
if not dp[i][j] and j%k==0 and dp[i1][j/k]:
dp[i][j]=True;
for e in a[i1][j/k]:
a[i][j].append(e)
a[i][j].append(k)
m=max(j,m);
print m
print a[o][m]

harshit.knit
October 30, 2014 s=list(raw_input())
f=False
for i in range(0,len(s)):
if s[i]=='?':
p=s[i1]
q=s[i+1]
f=True
if p!='a' and q!='a':
s[i]='a';
elif p!='b' and q!='b':
s[i]='b';
else:
s[i]='c';
if f:
print ''.join(s);
else:
print "Not Possible"

harshit.knit
October 29, 2014 A0 = 1;
A1 = 0;
B1 = 1;
C0 = 1;
C1 = 0;
n=int(raw_input())
for i in range(1,n):
(A0,A1,B1,C0,C1) = (C0,B1+C1,A0+C0,A0+C0,A1+B1+C1);
res = A0 + A1 + B1 + C0 + C1;
print res

harshit.knit
October 29, 2014 n=int(raw_input())
f=[2,3]
c=[3,7]
for i in range(2,n):
f.append(f[i1]+f[i2])
c.append(c[i1]+c[i2]+f[i])
print c[n1]

harshit.knit
October 29, 2014 #include <iostream>
using namespace std;
int main()
{
int T,n,l;
cin>>T;
for(int t=0;t<T;t++ )
{
cin>>n>>l;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<n;i++)
{
int pos=i;
for(int j=i+1;j<n;j++)
{
if(ji>l)
break;
if(a[pos]>=a[j])
pos=j;
}
if(i!=pos)
{
for(int k=pos;k>i;k)
swap(a[k],a[k1]);
l=(posi);
}
}
for(int i=0;i<n;i++)
cout<<a[i]<<" ";
cout<<"\n";
}
return 0;
}

harshit.knit
October 29, 2014 # your code goes here
u=raw_input()
k=int(raw_input())
def isalpha(c):
if ('A'<=c and c<='Z') or ('A'<=c and c<='Z'):
return True;
else:
return False;
def printKth(s,k):
l=0
n=''
i=0
while i<len(s):
if isalpha(s[i]):
l+=1;
if(l==k):
return s[i];
i+=1;
continue;
while i<len(s) and not isalpha(s[i]):
n+=s[i];
i+=1;
nl=int(n)*l;
n=''
if(k<=nl):
k=nl%k;
if k==0:
k=l;
return printKth(s,k)
else:
l=nl
print printKth(u,k)

harshit.knit
October 29, 2014 import sys
a=[int(x) for x in sys.stdin.readline().split('')]
b=[int(x) for x in sys.stdin.readline().split('')]
l=[]
for i in range(0,len(a)):
for j in range(i+1,len(b)):
if a[i]>b[j]:
l.append((a[i],b[j]));
print l

harshit.knit
October 29, 2014 solution in python.......
no of ways= fact(n)/(fact(p)*fact(q)*fact(s))
where p,q,s are no of characters of 3 types
# your code goes here
r=int(raw_input())
g=int(raw_input())
b=int(raw_input())
n=int(raw_input())
fact=[]
fact.append(1);
for i in range(1,1001):
fact.append(fact[i1]*i)
def getPartitions(e,n):
l=[]
if n==1:
p=[]
p.append(e);
l.append(p)
return l
for i in range(0,e+1):
lt=getPartitions(ei,n1);
for j in lt:
j.append(i);
l.append(j);
return l
def ways(r,g,b,n):
sum=0;
l=getPartitions(nrgb,3)
for i in l:
p=r+i[0]
q=g+i[1]
r=b+i[2]
print i
sum+=(((fact[n]/fact[p])/fact[q])/fact[r])
return sum
print ways(r,g,b,n);

harshit.knit
October 29, 2014 0 1 2 are numbers most used so they should be in both dice. and rest no u can distribute in dices and use only 6 (when needed 9 rotate it). 0 is in both dice becoz we need 01 02 03  09 date to be represented
0 1 2 3 4 5
0 1 2 6 7 8
Open Chat in New Window
 harshit.knit July 19, 2018