diff --git a/lib/practice_exercises.rb b/lib/practice_exercises.rb index 291e4e6..7fdcde0 100644 --- a/lib/practice_exercises.rb +++ b/lib/practice_exercises.rb @@ -1,13 +1,24 @@ -# Time Complexity: ? -# Space Complexity: ? +# Time Complexity: O(n) +# Space Complexity: O(1) def remove_duplicates(list) - raise NotImplementedError, "Not implemented yet" + new_array = [] + list.each do |i| + unless new_array[-1] == i + new_array << i + end + end + return new_array end -# Time Complexity: ? -# Space Complexity: ? +# Time Complexity: O(n) +# Space Complexity: O(1) def longest_prefix(strings) - raise NotImplementedError, "Not implemented yet" + min = strings.min + max = strings.max + string_pre = min.size.times do |i| + break i if min[i] != max[i] + end + min[0...string_pre] end