Skip to content

Commit

Permalink
Adding some instructions, contributors page & 99 DailyCodingChalanges…
Browse files Browse the repository at this point in the history
… solution
  • Loading branch information
FelipeCRamos committed Oct 2, 2023
1 parent 0fe85ed commit cf8351d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Contributors

- [FelipeCRamos](github.com/felipecramos)
39 changes: 39 additions & 0 deletions Python/99.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python3
"""
Problem:
Given an unsorted array of integers, find the length of the longest consecutive
elements sequence.
For example, given [100, 4, 200, 1, 3, 2], the longest consecutive element sequence is
[1, 2, 3, 4]. Return its length: 4.
Your algorithm should run in O(n) complexity.
Solution:
Time complexity: O(n)
Space complexity: O(n)
"""

from typing import List

# lces = Longest consecutive elements sequence
def lces(arr: List[int]) -> int:
unique_elements = set(arr)
longest_sequence = 0
# generating the longest sequence length
for i in range(len(arr)):
if (arr[i] - 1) not in unique_elements:
# current element is the starting element of a sequence
j = arr[i]
while j in unique_elements:
j += 1
# update longest sequence length
longest_sequence = max(longest_sequence, j - arr[i])
return longest_sequence


if __name__ == "__main__":
# test input/outputs
print(lces([100, 4, 200, 1]))
print(lces([100, 4, 200, 1, 3]))
print(lces([100, 4, 200, 2, 3]))
print(lces([100, 4, 200, 1, 3, 2]))
print(lces([100, 4, 200, 1, 3, 2, 5]))
4 changes: 4 additions & 0 deletions Python/python.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Hello contributors

This folder is where your python solutions should be placed!
Please give at least one input/output example for the problem! (can be inside of comments)

0 comments on commit cf8351d

Please sign in to comment.