Skip to content
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

Add q41 #26

Merged
merged 4 commits into from
Oct 2, 2022
Merged

Add q41 #26

merged 4 commits into from
Oct 2, 2022

Conversation

rakshitgondwal
Copy link
Contributor

@rakshitgondwal rakshitgondwal commented Oct 2, 2022

This is a template on how to fill out a PR properly.

Description

  • Language Used: C++

  • Approach Used:
    Put each number in its right place.
    For example:
    When we find 5, then swap it with A[4].
    At last, the first place where its number is not right, return the place + 1.

  • Question(s) Solved: 1

  • Issue(s) Closes: [FEATURE]: Add solution to Q41 to Q50 of Leetcode #24

We only need to keep track of which ones of the first n positive integers occur in the array. To do this with no extra space, we can treat the array like a boolean array, where sign(arr[i]) indicates whether the i-th positive integer is present or not. First, we replace all non-positive values with n + 1, since we'll only use these indices as storage space. Then, for every one of the first n positive numbers in the array, we turn the value at their corresponding index negative. Finally, all we need to do is check for the first positive value, which will give us the first missing positive. If we find no such index, then all natural numbers up to n are present, so we return n + 1.

Screenshot (331)

Related Issue

Acceptance Criteria

Type of Changes

Type
🐛 Bug fix
✨ New feature
🔨 Refactoring
💯 Add tests
🔗 Update dependencies
📜 Docs

Testing Steps / QA Criteria

@rakshitgondwal rakshitgondwal changed the title Rakshit1 Add q41 Oct 2, 2022
Copy link
Owner

@DugarRishab DugarRishab left a comment

Choose a reason for hiding this comment

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

Please give the file an extension

@DugarRishab DugarRishab self-requested a review October 2, 2022 16:29
Copy link
Owner

@DugarRishab DugarRishab left a comment

Choose a reason for hiding this comment

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

Give the file an extension

@rakshitgondwal
Copy link
Contributor Author

Give the file an extension

Done!

Copy link
Owner

@DugarRishab DugarRishab left a comment

Choose a reason for hiding this comment

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

GREAT !!

@DugarRishab DugarRishab merged commit 8a72626 into DugarRishab:main Oct 2, 2022
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.

[FEATURE]: Add solution to Q41 to Q50 of Leetcode
2 participants