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
1 change: 1 addition & 0 deletions Checkout Diagram.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mxfile host="app.diagrams.net" modified="2020-04-18T00:23:04.002Z" agent="5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36" etag="JzwEVP70qvwl2gAOnQiD" version="12.9.14" type="github"><diagram name="Page-1" id="9f46799a-70d6-7492-0946-bef42562c5a5">7Ztfc5s4EMA/jR9zw3/Do+3Eucyk00zcXp9lkEEJIA7k2O6nPwkkDEic7dY4l3PITAKLWMH+dsVqRUbmLNne5yCLvuAAxiNDC7Yj83ZkGLruOvQPk+wqydjjgjBHAW+0FyzQT8iFGpeuUQCLVkOCcUxQ1hb6OE2hT1oykOd40262wnG71wyEUBIsfBDL0h8oIJF4Lk3bn/gTojDiXbs2P7EE/muY43XK+xsZ5qrcqtMJELp4+yICAd40RObdyJzlGJNqL9nOYMxsK8xWXTfvOVvfdw5TcswFyXfHfnl4Rv7N+uHlx/bu2b5/udHNSs0biNfcIN8f+P2SnbBRsUFJDFJ6NI1IElOhTndXOCUL3ogdgxiFKd336Q3BnAreYE4QtfSEnyA4o1I/QnHwCHZ4zW67INSM4mga4Rz9pGqB6IOezgl3GkNvtViwK6lYo9IcFrTNk7CFXoseQUF4Gx/HMcgKtKxvOAF5iNIpJgQnvJF40jmK4xmOcV4aQIClWhlvGIjWAmmlP0E+34/BEsbT2kGEphSXNixIjl9rbytN2e4usKEbWNzEc5CgmAXXXzAPQAqE5Suj6EatsKHANZam49AzspNwv2Fs4LYh4k5zD3ECSb6jTfhZj/svj2/D4cebRrSImIgagaK7Ikp5hIa16r2X0h3uqKc4rSU5LdWziHCWoTSkJ6YglHyYPi1p++9Bf01QELDLp5sI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FULpu4O5W9UxtUnVd/t+qLh6OCE+6JPnW4Hs+DAsN5XXz+ce3aQXh3V4NDl5sK9Lp8ItFUuapqHwS0c72S/p4f5/BKpkZv+PGObdPw==</diagram></mxfile>
62 changes: 55 additions & 7 deletions lib/practice_exercises.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,61 @@

# Time Complexity: ?
# Space Complexity: ?
require "pry"
# Time Complexity: O(n2) because it is a nested loop. Each loop runs n number of times where n is the

Choose a reason for hiding this comment

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

Correct!

# length of the input test_array. Since the loops are nested, the loop will run n X n number of times.
# Space Complexity: O(1) because the amount of memory used does not change as the size of the input changes.
list = [1, 2, 2, 3, 3, 4]
def remove_duplicates(list)
raise NotImplementedError, "Not implemented yet"

i = 1
c = 0

while list[c] != nil
while list[c] == list[i]

Choose a reason for hiding this comment

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

This is a little odd and I think you could have i go beyond the bounds of the array. Something could break here.

list.delete_at(list[i])
i += 1
end
c += 1
end
return list
end

# Time Complexity: ?
# Space Complexity: ?

# Time Complexity: O(n^3)
# Space Complexity: O(1) because the amount of memory used does not change as the size of the input changes.


def longest_prefix(strings)
raise NotImplementedError, "Not implemented yet"

shortest_word = "pneumonoultramicroscopicsilicovolcanoconiosis"

strings.each do |string|
if string.length < shortest_word.length
shortest_word = string
end
end

prefix_array = []
strings.each_with_index do |string, index|
i = 0
shortest_word.each_char do |letter|
if letter != string[i]
prefix_array << shortest_word.slice(0..(i - 1))
end
i += 1
end
end

shortest_prefix = "pneumonoultramicroscopicsilicovolcanoconiosis"

prefix_array.each do |prefix|
if prefix.length < shortest_prefix.length
shortest_prefix = prefix
end
end

return shortest_prefix
end





1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'minitest'
require 'minitest/autorun'
require 'minitest/reporters'
require "minitest/skip_dsl"

Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new

Expand Down