jkatzwhitew
BAN USER
- 0of 0 votes
AnswersGiven an array of 100 numbers, find the (unique set) of duplicate values.
- jkatzwhitew in United States| Report Duplicate | Flag | PURGE
Linode Python Developer Python
Python3
inp = 'ababac'
sdict = {}
for i in range(len(inp)):
sdict[i] = inp[i:]
count = 0
LCP = {}
for sub_s in sdict.values():
for i in range(1,len(sub_s)+1):
if sub_s[:i] == inp:
LCP[sub_s] = len(inp)
count = 0
break
elif inp.startswith(sub_s[:i]):
count += 1
else:
LCP[sub_s] = count
count = 0
break
for key,value in LCP.items():
print('{}: {}'.format(key,value))
Python3
from collections import deque
inp = [1,1,0,1,0,0,0]
d = deque(inp)
tot0 = d.count(0)
tot1 = d.count(1)
while tot0 != tot1:
if tot0 > tot1:
if d[0] == 0:
d.popleft()
elif d[len(d)-1] == 0:
d.pop()
else:
d.popleft()
else:
if d[0] == 1:
d.popleft()
elif d[len(d)-1] == 1:
d.pop()
else:
d.popleft()
tot0 = d.count(0)
tot1 = d.count(1)
print(list(d))
This was the simplest answer I could come up with.
Python3
if a[j] - a[i] isn't abs:
_input = [9, 3, 4, 0, 5, 7, 4, 2, 1, 6]
i_index = _input.index(min(_input))
j_index = _input.index(max(_input[i_index:]))
print (i_index, j_index)
From looking at other people's comments, I get the sense that a[j] - a[i] is abs.
For Python3 this is what I did:
_input = ['a1','a2','a3','a4','a5','b1','b2','b3','b4','b5']
a = _input[:int(len(_input)/2)]
b = _input[int(len(_input)/2):]
d = []
for a,b in zip(a,b):
d.append(a)
d.append(b)
print(d)
There might be another way to simplify it, I couldn't find it.
Repkaylafgioia, Cloud Support Associate at Absolute Softech Ltd
Hi, I am Kayla from Elkins USA. I am working as Project management and I have professional 3-year experience in ...
Repewasam940, Backend Developer at Absolute Softech Ltd
I am a 29-year-old Investment Advisor from New York. I help people make the right investment decision. I met many ...
RepPatriciaNRowe, Consultant at ADP
Hi i am a Freelance Writer and Social Media Manager who helps finance professionals and Fin-tech startups build an audience ...
Repmarthajpatton, Data Scientist at AppPerfect
Managed a small team implementing gravy in Prescott, AZ. Developed several new methods for easy break up spells.Had some ...
Reprohitrana0777, Animator at AMD
I am work in free lancing as a editor in web developer. I also like play sports. I like kabaddi ...
Repashleymbosse, Associate at Accenture
I am an enthusiastic, hard-working and disciplined Catering Assistant with excellent track-record in working in the food industry. I am ...
I might be over simplifying but I used a deque and just popped the end that had the highest value.
- jkatzwhitew December 14, 2018[1,9,3,4,2,5,6,2]
def solution():
a=[]
b=[]
lst = input('Enter here --> ')
d = deque()
d.extend(lst)
while len(d)>0:
if len(d)>0:
if d[0]>d[len(d)-1]:
a.append(d.popleft())
else:
a.append(d.pop())
if len(d)>0:
if d[0]>d[len(d)-1]:
b.append(d.popleft())
else:
b.append(d.pop())
print 'Player A ', sum(a), ' ', a
print 'Player B ', sum(b), ' ', b
solution()
I got the same results as other people.