Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kelly #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
17 changes: 11 additions & 6 deletions lib/exercises.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

# This method will return an array of arrays.
# Each subarray will have strings which are anagrams of each other
# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(n)

Choose a reason for hiding this comment

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

If the strings are small enough, yes.

# Space Complexity: O(n)

def grouped_anagrams(strings)
raise NotImplementedError, "Method hasn't been implemented yet!"
grouped = Hash.new([])

strings.each.with_index do |word, i|
grouped[word.chars.sort.join] += [i]
end

return grouped.map { |key, indices| indices.map { |i| strings[i] } }

Choose a reason for hiding this comment

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

Why put the indexes into grouped instead of putting the words in the first place? Just seems a little odd.

end

# This method will return the k most common elements
Expand All @@ -17,14 +23,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