From 59c92973fa97e421bc994a63dedf78429d4bbeef Mon Sep 17 00:00:00 2001 From: Dominique Date: Sun, 15 Sep 2019 23:34:06 -0700 Subject: [PATCH 1/2] wave 2 finished --- lib/practice_exercises.rb | 62 ++++++++++++++++++++++++++++++++++----- test/test_helper.rb | 1 + 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/lib/practice_exercises.rb b/lib/practice_exercises.rb index 291e4e6..c362e52 100644 --- a/lib/practice_exercises.rb +++ b/lib/practice_exercises.rb @@ -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 +# 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] + 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 + + + + diff --git a/test/test_helper.rb b/test/test_helper.rb index 73622db..6f93c51 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,6 +2,7 @@ require 'minitest' require 'minitest/autorun' require 'minitest/reporters' +require "minitest/skip_dsl" Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From 5aba45d0ce5b7dee6c4d6de60d77be3eaf3e6879 Mon Sep 17 00:00:00 2001 From: dtaylor73 <44825337+dtaylor73@users.noreply.github.com> Date: Fri, 17 Apr 2020 19:23:06 -0500 Subject: [PATCH 2/2] Added Checkout Diagram.drawio --- Checkout Diagram.drawio | 1 + 1 file changed, 1 insertion(+) create mode 100644 Checkout Diagram.drawio diff --git a/Checkout Diagram.drawio b/Checkout Diagram.drawio new file mode 100644 index 0000000..6ba84ce --- /dev/null +++ b/Checkout Diagram.drawio @@ -0,0 +1 @@ +7Ztfc5s4EMA/jR9zw3/Do+3Eucyk00zcXp9lkEEJIA7k2O6nPwkkDEic7dY4l3PITAKLWMH+dsVqRUbmLNne5yCLvuAAxiNDC7Yj83ZkGLruOvQPk+wqydjjgjBHAW+0FyzQT8iFGpeuUQCLVkOCcUxQ1hb6OE2hT1oykOd40262wnG71wyEUBIsfBDL0h8oIJF4Lk3bn/gTojDiXbs2P7EE/muY43XK+xsZ5qrcqtMJELp4+yICAd40RObdyJzlGJNqL9nOYMxsK8xWXTfvOVvfdw5TcswFyXfHfnl4Rv7N+uHlx/bu2b5/udHNSs0biNfcIN8f+P2SnbBRsUFJDFJ6NI1IElOhTndXOCUL3ogdgxiFKd336Q3BnAreYE4QtfSEnyA4o1I/QnHwCHZ4zW67INSM4mga4Rz9pGqB6IOezgl3GkNvtViwK6lYo9IcFrTNk7CFXoseQUF4Gx/HMcgKtKxvOAF5iNIpJgQnvJF40jmK4xmOcV4aQIClWhlvGIjWAmmlP0E+34/BEsbT2kGEphSXNixIjl9rbytN2e4usKEbWNzEc5CgmAXXXzAPQAqE5Suj6EatsKHANZam49AzspNwv2Fs4LYh4k5zD3ECSb6jTfhZj/svj2/D4cebRrSImIgagaK7Ikp5hIa16r2X0h3uqKc4rSU5LdWziHCWoTSkJ6YglHyYPi1p++9Bf01QELDLp5sIEbjIgM90beg4KHlCAIqoPFDQXIHAC2wVJgAt3TSUmP49Wg/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