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

Trapping rain water problem using c++(Optimised) #567

Merged
merged 15 commits into from
Jul 22, 2021
Merged

Trapping rain water problem using c++(Optimised) #567

merged 15 commits into from
Jul 22, 2021

Conversation

vishvarana
Copy link
Contributor

@vishvarana vishvarana commented Jul 16, 2021

Have you read the Contributing Guidelines on Pull Requests?

Yes

Description

The problem is what most amount of rain water can the container store with different heights of the walls given as an array.

Checklist

  • I've read the contribution guidelines.
  • I've checked the issue list before deciding what to submit.

Related Issues or Pull Requests

#278

Fill up the DCP form

If you are a part of DCP 21, fill up this form after the PR is merged.

The links provided in the form will be checked thoroughly, if someone tries fooling around, strict actions will be taken against the individual.

@vishvarana vishvarana mentioned this pull request Jul 16, 2021
@sumitvajarinkar
Copy link
Contributor

@vishvarana
I run this solution but I am getting the wrong answer. Can you please check it?
The correct answer for input n=9, 1,8,6,2,5,4,8,3,7 is 19 and this code answer is 49.

@vishvarana
Copy link
Contributor Author

vishvarana commented Jul 17, 2021

The maximum heights chosen will be 8 and 7 that is 2nd and last element of the array.
The base will be 8-1=7(index of last element - 2nd element)
Water can only be filled upto the shorter of the two heights or it will overflow
Hence the area will be 7x7(shorter height*base)=49

@vishvarana
Copy link
Contributor Author

The idea is to maximize the area to trap water by both heights as well as base length.

@vishvarana
Copy link
Contributor Author

Smallest distinct window problem using c++
#317 issue

@vishvarana
Copy link
Contributor Author

Please review

@Saviour1001
Copy link
Contributor

@vishvarana add comments and explain the question in the code. Also add complexities.

@vishvarana
Copy link
Contributor Author

Trapping the rain water - I have explained the problem in previous comments
Time complexity - O(n)
Space complexity - O(1)

Smallest distinct window in a string containing all other characters of the string :
The problem focuses on 2 strings, one is the main, other being a part or substring. The idea is to find all the characters present in the part string in the main string and to print those contents of the string, which has this found characters
Time complexity - O(n^2)
Space complexity - O(1)

@vishvarana
Copy link
Contributor Author

There are 2 solutions added and both explained with complexities.

@Saviour1001
Copy link
Contributor

@vishvarana I am asking you to add the description and complexities as comments in the code file.

@smv1999
Copy link
Owner

smv1999 commented Jul 17, 2021

@vishvarana, Also place the file in appropriate folder.

@vishvarana
Copy link
Contributor Author

Required changes made.
Please review and let me know for any other improvements

@smv1999
Copy link
Owner

smv1999 commented Jul 18, 2021

Smallest distinct window problem using c++
#317 issue

Raise a new PR for #317

@vishvarana
Copy link
Contributor Author

New PR made
#651

Copy link
Owner

@smv1999 smv1999 left a comment

Choose a reason for hiding this comment

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

Then delete smallestdistinctwindow.cpp in this PR as it is not related to this. Also, delete the unnecessary (repetitive) files (which are not placed in any folder).

@smv1999 smv1999 requested a review from noviicee July 19, 2021 11:29
@vishvarana
Copy link
Contributor Author

Required changes done

Copy link
Owner

@smv1999 smv1999 left a comment

Choose a reason for hiding this comment

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

Great. Just add some comments to explain your core logic.

@vishvarana
Copy link
Contributor Author

Added comments in the cpp file

@Saviour1001
Copy link
Contributor

Good work @vishvarana

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.

4 participants