Skip to content
Open
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
29 changes: 23 additions & 6 deletions lib/practice_exercises.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(n)
# Space Complexity: O(1)
def remove_duplicates(list)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should have run the tests here.

raise NotImplementedError, "Not implemented yet"
if list.length == 0
return 0
end
unique_items = 1
list.length.times do |index|
if index != 0 && list[index - 1] != list[index]
unique_items +=1
end
end
return unique_items
end

# Time Complexity: ?
# Space Complexity: ?
# Did not have time to complete all the way

# Time Complexity: O(n^2)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given what you have here I would say O(m * n) where m is the length of the 1st string and n is the number of strings.

# Space Complexity: O(n)
def longest_prefix(strings)
raise NotImplementedError, "Not implemented yet"
prefix_string = ""
strings.first.length.times do |index|
string.each do |string|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String is undefined here.

string[index]
end
return prefix_string
end
end