frestuc
BAN USERShort and Simple Python solution with Backtracking:
def getMinLengthSubsequence(nums, sub):
def search(nums, sub, startn, starts):
if starts >= len(nums) or startn >= len(nums):
return 1, 1
for idx in range(startn, len(nums)):
if nums[idx] == sub[starts]:
if starts == len(sub)  1:
return idx, idx
start, end = search(nums, sub, idx + 1, starts + 1)
if start >= 0:
return idx, end
return 1, 1
start, end = 0, float('inf')
for idx in range(len(nums)):
if sub and nums[idx] == sub[0]:
startx, endx = search(nums, sub, idx, 0)
if startx != 1 and endx  startx < end  start:
start, end = startx, endx
return start, end

frestuc
August 05, 2016 def advance(nums, counts, i, j, X, Y):
while 0 <= i < j and counts[X] > counts[Y]:
if nums[j] == X:
counts[X] = 1
j = 1
else:
if nums[i] == X:
counts[X] = 1
i += 1
else:
i += 1
j = 1
return i, j
def largestContainingXandY(nums, X, Y):
counts = collections.Counter(nums)
i, j, res = 0, len(nums)  1, 0
while i < j:
i, j = advance(nums, counts, i, j, X, Y)
i, j = advance(nums, counts, i, j, Y, X)
if counts[X] == counts[Y]:
res = max(res, j  i + 1)
break
return res
nums = [7, 42, 5, 6, 42, 8, 7,5, 7, 6, 7]
nums1 = [7, 42, 7, 42, 7, 7, 42, 42, 7, 7, 7, 7, 7, 7, 42]
nums2 = [7, 7]
print(largestContainingXandY(nums1, 7, 42))

frestuc
August 04, 2016 def longestWithSumLessThanK(nums, k):
counts, i, res = 0, 0, float('inf')
for j in range(len(nums)):
counts += nums[j]
while i <= j and counts > k:
counts = nums[i]
i += 1
if counts <= k:
res = max(res, j  i + 1)
return res if res > float('inf') else None
nums = [1, 1, 1, 2, 1, 1, 1, 4, 4, 1, 2 ,3, 4, 1]
print(longestWithSumLessThanK(nums, 7))

frestuc
August 03, 2016 def generate(num):
res, s = [], list(int(x) for x in str(num))
for i in range(0, len(s)  1):
left = s[:i]
right = s[i+2:]
res += "".join(str(x) for x in left + [max(s[i], s[i+1])] + right),
# I got max 10 digits, so I run maximum 10 times the loop. Each loop takes O(n) time,
# Where n is the length (10). So at the end I have in the worst case a list of 10 elements each one having 10 digits. Getting the minimum will require me 10 comparisons each one taking 10 (I gotta compare every digit).
return min(res)
num = 233614
print(generate(num))

frestuc
August 03, 2016 One line in Python:
def check_patterns(words, p):
return [word
for word in words
if len(word) == len(p) and\
len(set(zip(word, p))) == len(set(word)) == len(set(p))
]
words = ["cdf", "too", "hgfdt" ,"paa"]
p = "abc"
p1 = "acc"
print(check_patterns(words, p))
print(check_patterns(words, p1))

frestuc
August 03, 2016
Repdeloresrdaniels, Cloud Support Associate at JDA
Crossed the country marketing wool in Nigeria. Was quite successful How to Get Girlfriend Back By Vashikaran Mantra . Spent a ...
RepJennyReimer, Dev Lead at Adobe
Badminton lover, coffee addict, guitarist, International Swiss style practitioner and TDC honorary member. Acting at the nexus of simplicity and ...
RepDiscover the cheapest packers and movers in Gurgaon at best price with smooth and hassle free relocation. We provide truck ...
RepSoccer lover, coffee addict, guitarist, International Swiss style practitioner and TDC honorary member. Acting at the nexus of simplicity and ...
Repmerrittmonique9, Android Engineer at AMD
I am Monique and working in high court from last 20 years.Handel many cases in my career.Build and ...
Repnyladsomerville, abc
Want to purchase best quality silencer at affordable price manufactured by top most trusted brand Innovative Arms.
Contact Stonefirearms now!
Rep
Rep
RepRichardWParks, Accountant at ADP
Open Chat in New Window
 frestuc August 23, 2016