Open
Conversation
abhiagx
requested changes
Oct 29, 2019
Owner
abhiagx
left a comment
There was a problem hiding this comment.
Please follow the Guidelines while making a pull request.
abhiagx
requested changes
Oct 29, 2019
| "Even though it might not be required in this problem, in some cases, you might be required to order the operations cleverly so that the numbers do not overflow. | ||
| For example, if you need to calculate n! / k! where n! is factorial(n), one approach is to calculate factorial(n), factorial(k) and then divide them. | ||
| Another approach is to only multiple numbers from k + 1 ... n to calculate the result. | ||
| Obviously approach 1 is more susceptible to overflows." |
Owner
There was a problem hiding this comment.
Wrap all these comments to new lines so that it does not trails the editor view.
| @@ -0,0 +1,52 @@ | |||
| /*There are certain problems which are asked in the interview to also check how you take care of overflows in your problem. | |||
Owner
There was a problem hiding this comment.
Begin problem statement on a newline after the block comment.
/*
There are certain problems...
| For example, if you need to calculate n! / k! where n! is factorial(n), one approach is to calculate factorial(n), factorial(k) and then divide them. | ||
| Another approach is to only multiple numbers from k + 1 ... n to calculate the result. | ||
| Obviously approach 1 is more susceptible to overflows." | ||
|
|
Owner
There was a problem hiding this comment.
File name must be RepeatAndMissingNumberArray.cpp.
Comment on lines
+36
to
+37
| int n =A.size(); | ||
| long long int sq1=0,sum1=0,sum2=0,sq2=0,x,a; |
Owner
There was a problem hiding this comment.
Give 1 space before and after each assignment operator.
a = 10;
| vector<int> Solution::repeatedNumber(const vector<int> &A) { | ||
| int n =A.size(); | ||
| long long int sq1=0,sum1=0,sum2=0,sq2=0,x,a; | ||
| vector <int> v(2,0); |
| long long int sq1=0,sum1=0,sum2=0,sq2=0,x,a; | ||
| vector <int> v(2,0); | ||
| int i; | ||
| for(i=0;i<n;i++){ |
Comment on lines
+41
to
+50
| sum2=sum2+long(i+1); | ||
| sq2=sq2+long(i+1)*long(i+1); | ||
| sum1=sum1+long(A[i]); | ||
| sq1=sq1+long(A[i])*long(A[i]); | ||
| } | ||
|
|
||
| x=(sq1-sq2)/(sum1-sum2); | ||
| a=(x+(sum1-sum2))/2; | ||
| v[0]=a; | ||
| v[1]=x-a; |
Owner
There was a problem hiding this comment.
- Give appropriate spacing, refer existing code files.
- Add code logical comments as what your each block is doing.
Owner
|
Hi @927tanmay, thanks for your PR. Kindly address the comments and follow https://github.com/cruxrebels/InterviewBit#how-to-contribute to get this merged! :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added new solution