forked from AdaGold/hash-practice
-
Notifications
You must be signed in to change notification settings - Fork 59
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
Abigail C - Rock #40
Open
ChaAbby
wants to merge
1
commit into
Ada-C15:master
Choose a base branch
from
ChaAbby:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Abigail C - Rock #40
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,18 +2,46 @@ | |
def grouped_anagrams(strings): | ||
""" 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 * m log(m)) (m is the max length of the word) | ||
Space Complexity: O(n) | ||
""" | ||
pass | ||
string_dict = {} | ||
# see if the sorted value is a key in the dict and if not add the element in the dict we are on as an array. | ||
for unsorted_word in strings: | ||
sorted_word = str(sorted(unsorted_word)) | ||
if sorted_word in string_dict: | ||
string_dict[sorted_word].append(unsorted_word) | ||
else: | ||
string_dict[sorted_word] = [unsorted_word] | ||
return list(string_dict.values()) | ||
# If the sorted value is in the dict add the element we are on to the key's value with the existing array. | ||
|
||
|
||
def top_k_frequent_elements(nums, k): | ||
""" This method will return the k most common elements | ||
In the case of a tie it will select the first occuring element. | ||
Time Complexity: ? | ||
Space Complexity: ? | ||
""" | ||
Comment on lines
20
to
25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Time/space complexity? You are sorting, is there a way without sorting? |
||
pass | ||
# Create an empty dict | ||
num_dict = {} | ||
# Iterate through nums and add count as the value of the dictionary. | ||
for num in nums: | ||
if num in num_dict: | ||
num_dict[num] += 1 | ||
else: | ||
num_dict[num] = 1 | ||
# Once we have the dict full we will find the values with the largest keys k times. | ||
sorted_list = set(sorted(num_dict.values(), reverse=True)[:k]) | ||
|
||
result = [] | ||
for key, value in num_dict.items(): | ||
if len(result) == k: | ||
return result | ||
if value in sorted_list: | ||
result.append(key) | ||
return result | ||
# return the keys in a list | ||
|
||
|
||
def valid_sudoku(table): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This solves the rows and columns, but not the 3x3 subgrids. |
||
|
@@ -25,5 +53,26 @@ def valid_sudoku(table): | |
Time Complexity: ? | ||
Space Complexity: ? | ||
""" | ||
pass | ||
rows_dict = {} | ||
col_dict = {} | ||
|
||
for i in range(9): | ||
col_dict[i] = {} | ||
for row_index in range(len(table)): | ||
rows_dict[row_index] = {} | ||
row = table[row_index] | ||
for index in range(len(row)): | ||
if row[index] == ".": | ||
continue | ||
else: | ||
if row[index] in rows_dict[row_index]: | ||
return False | ||
else: | ||
rows_dict[row_index][row[index]] = index | ||
|
||
if row[index] in col_dict[row_index]: | ||
return False | ||
else: | ||
col_dict[row_index][row[index]] = index | ||
return True | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Nice work.