Prashant
BAN USER 0of 0 votes
AnswersReverse an array in subset of N. Example:
 Prashant in India for Kindle
input: Array = [1,2,3,4,5,6,7,8,9], N = 3
output: [3,2,1,6,5,4,9,8,7] Report Duplicate  Flag  PURGE
Amazon Quality Assurance Engineer
def revRange(array):
revArray = []
for k in range(1, len(array)+1):
k = k*(1)
revArray.append(array[k])
return (revArray)
def revSubSet(l, N):
x = 0
rev_Sub_Set = []
for i in range(1,(len(l)//N)+1):
subSet = []
for j in range(x,N*i):
subSet.append(l[j])
x = N*i
y = (subSet)
rev_Sub_Set = rev_Sub_Set + y
subSet = []
leftOuts = []
for p in range(0, len(l)):
if l[p] not in rev_Sub_Set:
leftOuts.append(l[p])
if len(leftOuts) > 0:
y = revRange(leftOuts)
rev_Sub_Set = rev_Sub_Set + y
return (rev_Sub_Set)
l = [1,2,3,4,5,6,7,8,9]
N = 3
print (revSubSet(l,N))
def charDup(string):
char = []
charCount = []
for i in range(len(string)):
if string[i] not in char:
char.append(string[i])
counter = 0
for j in range(len(string)):
if string[i] == string[j]:
counter = counter +1
counter = str(counter)
charCount.append(counter)
outputStr = ''
for k in range(len(char)):
outputStr = outputStr + char[k]+ charCount[k]
return (outputStr)
a = 'aabbddbbccaad'
print (charDup(a))

Prashant
May 22, 2016 #Python Solution
s = [1, 2, 3, 3, 4, 5, 5, 5, 6]
x = []
for i in range (0, len(s)):
count = 0
if s[i] not in x:
x.append(s[i])
for j in range (0, len(s)):
if s[i] == s[j] :
count = count + 1
#print ("%s is repeated %d times" % (s[i],count))
e = "Salesforce is the best company to work fo"
d=e.lower()
z = []
for i in range (0, len(d)):
count = 0
if d[i] not in z:
z.append(d[i])
for j in range (0, len(d)):
if d[i] == d[j] :
count = count + 1
if count == 1:
print (d[i])
break
else:
print (d[i], count)

Prashant
April 23, 2016 string = "This is an example"
x = []
y = ""
for i in range(1, len(string)+1):
j = 1*i
y = y + string[j]
#print (y)
k = ''
for i in range(0, len(string)):
if string[i] != ' ':
k = k +string[i]
if (string[i] == ' ') or (i == (len(string)1)):
x.append(k)
k = ''
#print (x)
z = []
q = ''
for j in range(0, len(x)):
t = str(x[j])
for p in range(1,len(t)+1):
p = 1*p
q = q + t[p]
z.append(q)
q = ''
#print (z)
rev_str = ''
for g in range(0,len(z)):
rev_str = rev_str + ' ' + str(z[g])
print (rev_str.lstrip())

Prashant
April 23, 2016 Open Chat in New Window
 Prashant May 22, 2016