Skip to content

CC - 10 - #470

Open
shinjaneegupta wants to merge 1 commit into
super30admin:masterfrom
shinjaneegupta:master
Open

CC - 10#470
shinjaneegupta wants to merge 1 commit into
super30admin:masterfrom
shinjaneegupta:master

Conversation

@shinjaneegupta

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Interview Problem : Buy and Sell Stock (BuyAndSellStock2.py)

Your response should be comprehensive and helpful for the student to understand their mistakes and learn from them.

VERDICT: NEEDS_IMPROVEMENT


Interview Problem: Peeking Iterator (PeekingIterator.py)

Your solution is almost correct and follows a similar approach to the reference solution. However, there is a critical bug in the next() method: when peek_val is 0 (which is a valid integer), the condition if self.peek_val: evaluates to False, so it will not return the stored 0 and instead call the iterator's next() method. This is incorrect. You should change the condition to explicitly check for None, i.e., if self.peek_val is not None:. Similarly, in the hasNext() method, you correctly use self.peek_val is not None, which is good.

Also, in the next() method, when peek_val is not None, you should store it in a temporary variable (like to_return), set peek_val to None, and then return the temporary variable. This part is correct, but the condition needs to be fixed.

Another minor point: the variable name it_ is not very descriptive. You could name it iterator for clarity, but this is a style choice.

To fix the issue, update the next() method as follows:

    def next(self):
        if self.peek_val is not None:
            to_return = self.peek_val
            self.peek_val = None
            return to_return
        return self.it_.next()

With this change, the solution will handle all integers correctly.

VERDICT: NEEDS_IMPROVEMENT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants