koolkhush
BAN USER
Comments (7)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
Python:
def interscetion(A,B):
len1 = len(A)
len2 = len(B)
C = []
if len1 == 0 or len2 == 0:
return C
dict1 = {}
dict2 = {}
for i in range(0,len1):
if A[i] in dict1:
dict1[A[i]] += 1
else:
dict1[A[i]] = 1
for i in range(0,len2):
if B[i] in dict2:
dict2[B[i]] += 1
else:
dict2[B[i]] = 1
for keys,values in dict1.items():
if keys in dict2:
dict2values = dict2[keys]
if dict2values <= values:
temp = dict2values
else:
temp = values
for i in range (0,temp):
C.append(keys)
return C
C = interscetion(A,B)
print C

koolkhush
February 12, 2018 Comment hidden because of low score. Click to expand.
0
of 0 vote
Python:
s = 'banana'
list1 = ['bana', 'apple', 'banaba', 'bonanza', 'banamf', 'banana']
def check(s,list1):
if len(s) == 0 or len(list1) == 0:
return False
list2 = []
for items in list1:
if len(s) == len(items):
count = 0
for i in range(0,len(s)):
if s[i] != items[i]:
count += 1
if count <= 1:
list2.append(items)
return list2
list2 = check(s,list1)
if len(list2) > 0:
print "True"
print list2

koolkhush
February 12, 2018 Comment hidden because of low score. Click to expand.
0
of 0 vote
Python Code. Works for below input :
s = "bedbathandbeyond"
list1 = ['bed','bath','and','beyond']
Output = true
s = "bedbathandbeyond"
list1 = ['and','bath','and','beyond']
Output = false
s = "bedbathandbeyond"
list1 = ['beyond','bath','and','bed']
Output = False
def check(s,dict1):
len1 = len(s)
len2 = len(list1)
if len1 == 0 or len2 == 0:
return False
sum1 = 0
for items in list1:
sum1 = sum1 + len(items)
if sum1 != len1:
return False
s1 = s
for items in list1:
#print "1st step"
#print items,s1
s2,flag = subs(items,s1)
#print "2nd step"
print items, flag, s2
s1 = s2
if flag == False:
return False
if len(s2) == 0:
return True
def subs(items,s1):
len1 = len(items)
len2 = len(s1)
print items, s1
for i in range(0,len2):
if s1[i] == items[0]:
if i+len1 <= len2:
temp = ''
for j in range (i,i+len1):
temp = temp + s1[j]
if temp == items:
s2 = ''
#print i+len1, len2
if i != 0:
for l in range (0,i):
s2 = s2+s1[l]
for k in range (i+len1, len2):
#print s2, s1[k]
s2 = s2+s1[k]
return s2, True
return s1,False
flag = check (s,list1)
print flag

koolkhush
February 09, 2018 Comment hidden because of low score. Click to expand.
0
of 0 vote
Code in Python. Works for all above inputs.
#s = '999'
#k = 1
#output = 9,99 or 99,9 : 99
#s = '999'
#k = 2
#output = 9,9,9 : 9
s = '857'
k = 1
#output = 8,57 or 85,7 : 85
def check(s,k):
len1 = len(s)
if len1 <= k:
return None
#pointer = len1/(k+1)
#print pointer
list1 = []
s1 = ''
s2 = ''
for i in range (0,k):
list1.append(s[i])
for i in range (k,len1):
s1 = s1 + s[i]
list1.append(s1)
for i in range(len11,len11k,1):
list1.append(s[i])
for i in range(0,len1k):
s2 = s2+s[i]
list1.append(s2)
temp = 0
for items in list1:
intitems = int(items)
if intitems > temp:
temp = intitems
return temp
highest = check(s,k)
print highest

koolkhush
February 09, 2018 Comment hidden because of low score. Click to expand.
0
of 0 vote
Python : Used Stack and Dictionary. Complexity O(N)
s1 = 'aabdceaaabbbcd'
#output = dcbae
s2 = 'aaaabbcddddccbbdaaeee'
#output = eadbc
s3 ='aaafffcccddaabbeeddhhhaaabbccddaaaa'
#output = adcbhef
def check(s1):
len1 = len(s1)
if len1 <= 1:
return s1
dict1 = {}
count = 0
list1 = []
for i in range(len11,0,1):
if s1[i] in dict1:
dict1[s1[i]] = count
count += 1
else:
dict1[s1[i]] = count
count += 1
if s1[i] not in list1:
list1.append(s1[i])
print dict1
print list1
s2 = ''
for items in list1:
s2 = s2 + items
print s2
check(s3)

koolkhush
February 09, 2018 Comment hidden because of low score. Click to expand.
0
of 0 vote
Python
def takeinput():
s = raw_input ("Please Enter the String :")
n = input ("Please enter 'n' :" )
n = int(n)
len1 = len(s)
if len1 <= n:
print "Shifts cannot be performed on this string!!"
s1 = leftshift(s,n)
s2 = rightshift(s,n)
return s1,s2
def leftshift(s,n):
len1 = len(s)
s1 = ''
for i in range(n,len1):
s1 = s1+s[i]
for i in range(0,n):
s1 = s1+s[i]
return s1
def rightshift(s,n):
len1 = len(s)
s2 = ''
for i in range (len1n, len1):
s2 = s2 + s[i]
for i in range (0, len1n) :
s2 = s2+s[i]
return s2
s1,s2 = takeinput()
print ("Left Shift on String is %s :" , s1)
print ("Right Shift on String is %s :", s2)

koolkhush
February 08, 2018 Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Open Chat in New Window
Open Chat in New Window
Python:
 koolkhush February 12, 2018