-
Notifications
You must be signed in to change notification settings - Fork 61
Completed Q1, Q2 and Q3 solutions #3
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @Disha-Kumar, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request delivers the initial implementations for three distinct algorithmic problems. It provides a solution for identifying 'stable' characters in a string, a method for calculating the effective length of a sequence after specific cancellation rules, and an algorithm to detect 'overloaded' users based on event frequency within a time window. The changes primarily involve adding the core logic to previously empty function stubs. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request provides solutions for three programming questions. The solution for Q2 is well-implemented. However, the solutions for Q1 and Q3 contain critical bugs. In Q1, the logic fails to check if a character appears at least twice before considering it stable. In Q3, there are several issues: the default parameters are incorrect, the window and threshold logic is flawed, and the function returns a list instead of the required set. I've provided specific comments and suggestions to address these problems.
| while i + block_length < n and s[i + block_length] == current_char: | ||
| block_length += 1 | ||
|
|
||
| if freq[current_char] == block_length: |
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.
The current implementation incorrectly identifies characters that appear only once as stable. The problem description states that a character must appear at least twice to be considered stable. For example, for the input "abc", the function will return 'a', but the expected output is None. You need to add a check to ensure the character count is greater than one.
| if freq[current_char] == block_length: | |
| if freq[current_char] == block_length and block_length > 1: |
| while times[right] - times[left] > window: | ||
| left += 1 | ||
|
|
||
| if right - left + 1 > threshold: |
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.
There are two logic errors here that cause incorrect behavior based on the problem description:
- The window check
> windowon line 65 should be>= window. The problem asks for events within a 10-second window (i.e., duration< 10). Your current logic incorrectly includes events with a duration of exactly 10 seconds. - The event count check
> thresholdon line 68 is incorrect for a "3 or more" events condition. It should be>= thresholdto correctly include cases with exactlythresholdnumber of events.
| while times[right] - times[left] > window: | |
| left += 1 | |
| if right - left + 1 > threshold: | |
| while times[right] - times[left] >= window: | |
| left += 1 | |
| if right - left + 1 >= threshold: |
| pass | ||
| from collections import defaultdict | ||
|
|
||
| def find_overloaded_users(events, threshold=10, window=60): |
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.
The default values for threshold and window do not match the problem's requirements of "3 or more events within a 10-second window". The defaults should be 3 for the event threshold and 10 for the time window.
| def find_overloaded_users(events, threshold=10, window=60): | |
| def find_overloaded_users(events, threshold=3, window=10): |
| overloaded_users.append(user_id) | ||
| break | ||
|
|
||
| return sorted(overloaded_users) |
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.
No description provided.