Skip to content

Problem1.py - #464

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

Problem1.py#464
sejalrj wants to merge 1 commit into
super30admin:masterfrom
sejalrj:master

Conversation

@sejalrj

@sejalrj sejalrj commented Feb 21, 2026

Copy link
Copy Markdown

Submitting placeholder answer as I do not remember what the exact question was and I have attended and passed all the 15 mock interviews.

@super30admin

Copy link
Copy Markdown
Owner

Strengths:

  • The code for the word distance problem is clean and efficient for that problem.
  • The student mentions having passed all mock interviews, which shows commitment.

Areas for Improvement:

  • It is crucial to ensure that the solution matches the problem statement. Please double-check the problem requirements before writing code.
  • For the given stock problem, a recursive approach with memoization or a greedy approach would be more efficient. The greedy approach (capturing every upward movement) is optimal with O(n) time and O(1) space.
  • Practice problem identification and make sure to understand the problem fully before starting to code.

Suggested Solution for the Stock Problem:
A simple greedy approach can be used since multiple transactions are allowed. We can capture every positive price difference between consecutive days.
Example code in Python:

class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        profit = 0
        for i in range(1, len(prices)):
            if prices[i] > prices[i-1]:
                profit += prices[i] - prices[i-1]
        return profit

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