Skip to content

Create first_missing_positive.py #11186

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

Closed

Conversation

moaldeen
Copy link
Contributor

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

@moaldeen moaldeen marked this pull request as draft November 27, 2023 22:22
@moaldeen moaldeen marked this pull request as ready for review November 27, 2023 22:28
@algorithms-keeper algorithms-keeper bot added the awaiting reviews This PR is ready to be reviewed label Nov 27, 2023
@cclauss
Copy link
Member

cclauss commented Nov 29, 2023

>>> def x(nums):
...     return sorted(set(range(1, max(nums) + 2)) - set(nums))[0]
...
>>> x([2, 5, -10, 8, 4, 6, 1, 9])
3
>>> x([7, 8, 9, 11, 12])
1
>>> x([3, 4, -1, 1])
2
>>> x([1, 2, 0])
3

:return: The smallest missing positive integer.

Examples:
>>> first_missing_positive([1, 2, 0])
Copy link
Member

@cclauss cclauss Nov 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add doctests for

>>> first_missing_positive([])
>>> first_missing_positive([0])
>>> first_missing_positive([1])
>>> first_missing_positive([1.1, 2.2, 3.3])
>>> first_missing_positive([-1, -2, -3])
>>> first_missing_positive("ABC")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the feedback .. i have done it

@cclauss cclauss added awaiting changes A maintainer has requested changes to this PR and removed awaiting reviews This PR is ready to be reviewed labels Nov 29, 2023
@@ -1,6 +1,6 @@
def first_missing_positive(nums: list[int]) -> int:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing type hints is a bad idea.

@algorithms-keeper algorithms-keeper bot added awaiting reviews This PR is ready to be reviewed and removed awaiting changes A maintainer has requested changes to this PR labels Nov 29, 2023
Copy link
Contributor Author

@moaldeen moaldeen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hint was added

:return: The smallest missing positive integer.

Examples:
>>> first_missing_positive([1, 2, 0])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the feedback .. i have done it

Copy link
Contributor Author

@moaldeen moaldeen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed the hint

Copy link
Contributor Author

@moaldeen moaldeen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hint added

@algorithms-keeper algorithms-keeper bot added awaiting changes A maintainer has requested changes to this PR and removed awaiting reviews This PR is ready to be reviewed labels Nov 29, 2023
@algorithms-keeper algorithms-keeper bot added awaiting reviews This PR is ready to be reviewed and removed awaiting changes A maintainer has requested changes to this PR labels Nov 29, 2023
@moaldeen moaldeen requested a review from cclauss November 29, 2023 23:09
@moaldeen
Copy link
Contributor Author

moaldeen commented Dec 3, 2023

@cclauss i have made the adjustments, could you please review it. ? i really appreciate it.

@moaldeen moaldeen marked this pull request as draft December 5, 2023 15:44
@moaldeen moaldeen marked this pull request as ready for review December 5, 2023 15:44
@moaldeen moaldeen closed this Dec 5, 2023
@moaldeen moaldeen reopened this Dec 5, 2023
@moaldeen moaldeen closed this Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reviews This PR is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants