Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Python/faulty_keyboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Faulty Keyboard

class Solution(object):
def finalString(self, s):
result = ''
is_reversed = False

for char in s:
if char == 'i':
is_reversed = not is_reversed
else:
if is_reversed:
result = char + result
else:
result += char

if is_reversed:
result = result[::-1]

return result

solution = Solution()
print(solution.finalString("string"))
13 changes: 13 additions & 0 deletions Python/length_of_longest_subarray_with_at_most_k_frequency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution(object):
def maxSubarrayLength(self, nums, k):
n, left, result = len(nums), 0, 0
freq = defaultdict(int)

for right in range(n):
freq[nums[right]] += 1
while freq[nums[right]] > k:
freq[nums[left]] -= 1
left += 1
result = max(result, right - left + 1)

return result
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,6 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
- [Subarray Product Less Than K](Python/subarray_product_less_than_k.py)
- [Valid Parentheses](Python/valid_parentheses.py)
- [Remove Element](Python/remove_element.py)
- [Remove Duplicates from Sorted Array](Python/remove_duplicates_from_sorted_array.py)
- [Remove Duplicates from Sorted Array](Python/remove_duplicates_from_sorted_array.py)
- [Faulty Keyboard](Python/faulty_keyboard.py)
- [Length of Longest Subarray With at Most K Frequency](Python/length_of_longest_subarray_with_at_most_k_frequency.py)