Skip to content

Instantly share code, notes, and snippets.

@adamgarcia4
Created August 10, 2020 20:57
Show Gist options
  • Save adamgarcia4/925394ca9e86025ec22e78fb7aa89305 to your computer and use it in GitHub Desktop.
Save adamgarcia4/925394ca9e86025ec22e78fb7aa89305 to your computer and use it in GitHub Desktop.
class Solution:
def getHappyString(self, n: int, k: int) -> str:
'''
Input:
n - the length of a happy string
k - I want to return the 'k'th item
Output:
The 'k'th happy string of length 'n'
Constraints:
Only choose letters from {a,b,c}
No subsequent letters in a row
Approach:
Choices
Iterate through (a,b,c) on every level.
We don't use 'idx' and 'idx + 1'
Bounding Function
if i != 0 and partial[i] == partial[i - 1]:
Prune
Goal:
If len(partial) == n:
if counter == k: (goal 1)
return partial
result.append(partial) (goal 2)
Output:
If using goal 1, then just return this
If using goal 2, return result[k - 1]
Choices:
for i in range(len(letters)):
# Bounding function
# check for duplicates
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment