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

Modified code Largest Sum Contiguous Subarray [C, Java] #421

Closed
wants to merge 13 commits into from

Conversation

jitendra3109
Copy link
Member

Fixes #420

By submitting this pull request I confirm I've read and complied with the below declarations.

  • I have read the Contribution guidelines and I am confident that my PR reflects them.
  • I have followed the coding guidelines for this project.
  • My code follows the skeleton code structure.
  • This pull request has a descriptive title. For example, Added {Algorithm/DS name} [{Language}], not Update README.md or Added new code.
  • This pull request will be closed if I fail to update it even once in a continuous time span of 7 days.

@@ -14,12 +14,9 @@ public static int largestSumContiguousSubarray(int[] array) { // maximum sum
prevSum = array[0]; // initialize current sum amd previous sum
currentSum = array[0];
for (i = 1; i < array.length; i++) {
Copy link
Member

@aashutoshrathi aashutoshrathi Jul 23, 2017

Choose a reason for hiding this comment

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

i can be declared here only like for (int i = 1; i < array.length; i++) and remove line 13

@aashutoshrathi aashutoshrathi changed the title Modified code Largest Sum Contiguous Subarray [C,Java] Modified code Largest Sum Contiguous Subarray [C, Java] Jul 23, 2017
}

int main() {
int array[] = {-2, 1, -3, 4, -1, 2, 1, -5, 4, 5};
printf("%d", largestSumContinousSubArray(array, 10));
Copy link
Member

@aashutoshrathi aashutoshrathi Jul 23, 2017

Choose a reason for hiding this comment

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

Either change Continous to Continuous (as previous one is type) or Contiguous (as filename suggests).

Copy link
Member

Choose a reason for hiding this comment

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

Instead of 10 place size there; where size = sizeof(array)/sizeof(array[0]);

Copy link
Member

@aashutoshrathi aashutoshrathi left a comment

Choose a reason for hiding this comment

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

See Comments

}

int main() {
int array[] = {-2, 1, -3, 4, -1, 2, 1, -5, 4, 5};
printf("%d", largestSumContinousSubArray(array, 10));
Copy link
Member

Choose a reason for hiding this comment

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

Instead of 10 place size there; where size = sizeof(array)/sizeof(array[0]);

}

int main() {
int array[] = {-2, 1, -3, 4, -1, 2, 1, -5, 4, 5};
printf("%d", largestSumContinousSubArray(array, 10));
Copy link
Member

Choose a reason for hiding this comment

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

Instead of %d use %d\n

@aashutoshrathi aashutoshrathi self-assigned this Jul 23, 2017
@iiitv iiitv deleted a comment Jul 25, 2017
@iiitv iiitv deleted a comment Jul 27, 2017
@iiitv iiitv deleted a comment Jul 27, 2017

int main() {
int array[] = {-2, 1, -3, 4, -1, 2, 1, -5, 4, 5};
int size = sizeof(array)/sizeof(array[0]);
Copy link
Member

Choose a reason for hiding this comment

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

add whitespace around / and its done. 👍

@iiitv iiitv deleted a comment Jul 28, 2017
@@ -1,25 +1,27 @@
#include <stdio.h>
#include <stdlib.h>

int largestSumContinousSubArray(int arr[], int size) {
int largestSumContiguousSubArray(int arr[], int size) {
Copy link
Member

@aashutoshrathi aashutoshrathi Jul 28, 2017

Choose a reason for hiding this comment

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

It should be largestSumContiguousSubarray. i.e. same as filename.

Copy link
Member

Choose a reason for hiding this comment

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

@jsroyal We should rename the file to ...SubArray.c

@iiitv iiitv deleted a comment Aug 17, 2017
@iiitv iiitv deleted a comment Aug 17, 2017
int array[10];
for (int k = 0; k < 10; k++) {
array[k] = rand() % 10;
int max(int first, int second) {
Copy link
Member

Choose a reason for hiding this comment

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

#define max(a,b) (((a)>(b)) ? (a) : (b))

Better use this.

@iiitv iiitv deleted a comment Aug 21, 2017

int largestSumContinousSubArray(int arr[], int size) {
int largestSumContiguousSubarray(int arr[], int size) {
Copy link
Member

Choose a reason for hiding this comment

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

@jsroyal Sir please fix the function name as per C guidelines.

@singhpratyush
Copy link
Member

@jsroyal: Please reopen if you wish to continue.

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.

Test case failed -> Largest Sum Contiguous Subarray
7 participants