-
Notifications
You must be signed in to change notification settings - Fork 29
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
Shubha 🧟♀️ #19
base: master
Are you sure you want to change the base?
Shubha 🧟♀️ #19
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,18 @@ | ||
|
||
# Time Complexity: ? | ||
# Space Complexity: ? | ||
# Time Complexity: O(n) | ||
# Space Complexity: O(1) | ||
def max_sub_array(nums) | ||
return 0 if nums == nil | ||
|
||
raise NotImplementedError, "Method not implemented yet!" | ||
return nil if nums == nil || nums.empty? | ||
max = nums[0] | ||
curr_max = nums[0] | ||
(1...nums.length).each do |i| | ||
curr_max = curr_max + nums[i] | ||
if nums[i] > curr_max | ||
max = nums[i] if nums[i] > max | ||
curr_max = nums[i] | ||
else | ||
max = curr_max if curr_max > max | ||
end | ||
end | ||
return max | ||
Comment on lines
+5
to
+17
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. Very elegantly done |
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
|
||
|
||
# Time complexity: ? | ||
# Space Complexity: ? | ||
# Time complexity: O(n) | ||
# Space Complexity: O(n) | ||
def newman_conway(num) | ||
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. 👍 |
||
raise NotImplementedError, "newman_conway isn't implemented" | ||
seq = [0, 1, 1] | ||
raise ArgumentError if num <= 0 | ||
return seq[1..num].join(' ')if num == 1 || num == 2 | ||
(3..num).each do |i| | ||
seq[i] = seq[seq[i-1]] + seq[i - seq[i - 1]] | ||
end | ||
return seq[1..num].join(' ') | ||
end | ||
Comment on lines
+6
to
13
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. Nicely done! |
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.
👍