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

Sidhant prs #1518

Merged
merged 4 commits into from
Dec 27, 2020
Merged

Sidhant prs #1518

merged 4 commits into from
Dec 27, 2020

Conversation

Sidhant-Gupta
Copy link
Contributor

@Sidhant-Gupta Sidhant-Gupta commented Dec 13, 2020

Have you read the [Contributing Guidelines on Pull Requests]

Yes,I have read.

(Write your answer here.)

Description

Dutch National Flag Algorithm- Implemented in C++.

Checklist

  • I've read the contribution guidelines.
  • I've checked the issue list before deciding what to submit.
  • Dutch National Flag algo -Implemented

Related Issues or Pull Requests

(Write your answer here.)

@Sidhant-Gupta
Copy link
Contributor Author

This pr is related to the issue - Dutch National Flag Implementation #1462

@HarshCasper
Copy link
Owner

Hello @Sidhant-Gupta

If you are picking problems for CP/DS-Algo Portals, please add their link.

The above problem is from a LeetCode Problem.

@Sidhant-Gupta
Copy link
Contributor Author

I've made the desired changes. Please review it.

Comment on lines 3 to 25
//
// PROBLEM STATEMENT- https://leetcode.com/problems/sort-colors/

// Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue.
// Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.
// In simpler words sort an array containing 0,1,2.

// Solve the problem with a one-pass algorithm using only O(1) constant space?

// TEST CASE-
// Input:
// n=6
// nums = [2,0,2,1,1,0]
// Output: [0,0,1,1,2,2]

// Input:
// n=3
// nums = [2,0,1]
// Output: [0,1,2]

// The bruteforce approach - Sort the vector in nlogn time

// ************************DUTCH_NATIONAL_FLAG ALGORITHM***********************************
Copy link
Owner

Choose a reason for hiding this comment

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

Shift the Comments above any lines of code

Comment on lines 12 to 21
// TEST CASE-
// Input:
// n=6
// nums = [2,0,2,1,1,0]
// Output: [0,0,1,1,2,2]

// Input:
// n=3
// nums = [2,0,1]
// Output: [0,1,2]
Copy link
Owner

Choose a reason for hiding this comment

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

Shift the sample I/O after the Code ends

med++;
}
else{
// swap(nums[med],nums[high]);
Copy link
Owner

Choose a reason for hiding this comment

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

Remove any instances of commented lines of code. We prefer to have comments over the code but not commented code


// COMPLEXITY ANALYSIS-
// Time= O(N)
// space=O(1)
Copy link
Owner

Choose a reason for hiding this comment

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

Add a line at the EOF

@Sidhant-Gupta
Copy link
Contributor Author

I've made all the requested changes. Kindly review @HarshCasper

@HarshCasper HarshCasper merged commit ca093f6 into HarshCasper:master Dec 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants