frestuc
BAN USER
Short 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
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))
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))
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))
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))
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 ...
Repamyfreynold, abc at ADP
I am Amy . I work as an Spray machine operator in Sofia Express . I’m lecturing about lost love back ...
RepRobin Strain, Consultant
I am from New york. I am 26 year old. I work in a Central Hardware as a Worker compensation ...
RepI am randy, 29 year old and I am doing a job. I am doing a job as a plant ...
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 ...
Repmarkhlee8, Research Scientist at Bank of America
I am a cooking Instructor in New York USA, I Have a degree from the prestigious Culinary Arts Institute of ...
Repmarilynarhea, Computer Scientist at ABC TECH SUPPORT
I live my life very happily by god grace and I am working as a Gaming machine servicer and my ...
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 ...
Repjasonmcarrier, Analyst at Abs india pvt. ltd.
Hello, I live in Houston and I am working as a Convention planner in Roberd's company, I also part ...
Repsujijaa565, AT&T Customer service email at ABC TECH SUPPORT
My name is suji. I am working as a Suadela Investment in Tulsa USA . I identify and establish a new ...
Repjohndbutler0, Aghori Mahakal Tantrik at BMO Harris Bank
I consider myself to be driven, proactive, hard working, a team player, creative and absolutely passionate person! I am strong ...
Repsusancmeans, Apple Phone Number available 24/7 for our Customers at Absolute Softech Ltd
I am Susan from Bronx, I am working as a Business management analyst in Brendle's company. I Have a ...
RepJenniferSRoe, Android test engineer at Accolite software
I am Jennifer from Dublin. I am Photographer, I have experienced in all different kinds of photography -Strong aesthetic sense ...
Repvickiwgerber, Member Technical Staff at Boomerang Commerce
I am Vicki From San Antonio USA, I am working as an Interior decorator in Golden Joy company. I have ...
RepEdithJHarden, Random at Axiom Sources
Je suis un professionnel de la gestion des soins de santé avec 2 ans d'expérience en supervision d'établissements ...
RepDiscover the cheapest packers and movers in Gurgaon at best price with smooth and hassle free relocation. We provide truck ...
Repkellydbrown23, Jr. Software Engineer at Auto NInja
I live in College Park USA with my family, and my current job is clerk in Luria’s company. I ...
RepSoccer lover, coffee addict, guitarist, International Swiss style practitioner and TDC honorary member. Acting at the nexus of simplicity and ...
Reploreleijhansen, Aghori Mahakal Tantrik at ABC TECH SUPPORT
I am Lorelei.I am working in a store as a Bonus clerk promoting the development, and implementation and solutions ...
Repjosephcday6, Android Engineer at Absolute Softech Ltd
I am SEO Executive in Elek-Tek company. I live in Morgantown USA. I won’t write any details about Best ...
Repjohnagragg0, cox customer service at Deloitte Consulting LLP
I am friendly, I am a hard worker, even through difficult circumstances, I want to know about How to identify ...
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 ...
RepPriscillaRYoung, Aghori Mahakal Tantrik at Absolute Softech Ltd
Hi, I am Priscilla from California. I am working as a Business management consultant in Quality Merchant Services company. I ...
Repnyladsomerville, abc
Want to purchase best quality silencer at affordable price manufactured by top most trusted brand Innovative Arms.
Contact Stonefirearms now!
Repethelynfrose, Computer Scientist at 247quickbookshelp
Hello, I am Ethelyn and I live in Lake Worth, USA. I am working as a Dog Trainer and Dog ...
RepSarahSKelly, Game Programmer at Akamai
I am Professor, and I am also a skilled fiction writer. I have a collection of novels published in the ...
Rep
Rep
Repmarywwaldrop7, Computer Scientist at Chelsio Communications
I am Mary ,working in the field of training and development coordinator for three years, focusing on teaching English as ...
RepRichardWParks, Accountant at ADP
Repmarkemorgan007, Applications Developer at Big Fish
I am Mark From Fresno city in USA.I working as a tour guide and also help for make a ...
Open Chat in New Window
- frestuc August 23, 2016