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: 25 additions & 4 deletions lib/exercises.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,29 @@
# Space Complexity: ?

def grouped_anagrams(strings)

Choose a reason for hiding this comment

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

This definitely works, but what is the time/space complexity.

Also could you do this more efficiently with a hash?

raise NotImplementedError, "Method hasn't been implemented yet!"
return [] if strings.empty?
n = strings.length - 1
array_store_anagrams = [[strings[0]]]
i = 1
while i <= n
matched = false
array_store_anagrams.length.times do |j|
array = array_store_anagrams[j]
if array[0].split("").sort.join == strings[i].split("").sort.join

Choose a reason for hiding this comment

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

You're sorting both sides here... maybe this could be opimized...

array_store_anagrams[j] << strings[i]
matched = true
break
else
matched = false
end
end
if matched == false
new_array = [strings[i]]
array_store_anagrams << new_array
end
i += 1
end
return array_store_anagrams
end

# This method will return the k most common elements
Expand All @@ -17,14 +39,13 @@ def top_k_frequent_elements(list, k)
raise NotImplementedError, "Method hasn't been implemented yet!"
end


# This method will return the true if the table is still
# a valid sudoku table.
# Each element can either be a ".", or a digit 1-9
# The same digit cannot appear twice or more in the same
# The same digit cannot appear twice or more in the same
# row, column or 3x3 subgrid
# Time Complexity: ?
# Space Complexity: ?
def valid_sudoku(table)
raise NotImplementedError, "Method hasn't been implemented yet!"
end
end