Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Java Urgent Help

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Java Urgent Help

    I have a java question. Can anyone help me solve it please. Much appreciated

    A zero-indexed array A consisting of N integers is given. A triplet (P, Q, R) is called a triangle if 0 ≤ P < Q < R < N and:
    A[P] + A[Q] > A[R],
    A[Q] + A[R] > A[P],
    A[R] + A[P] > A[Q].
    The perimeter of such a triangle equals A[P] + A[Q] + A[R]. For example, consider the following array A:
    A[0] = 10
    A[1] = 2
    A[2] = 5
    A[3] = 1
    A[4] = 8
    A[5] = 20
    Triplet (0, 2, 4) is a triangle and its perimeter equals 10 + 5 + 8 = 23. There is no other triangle in this array with a larger perimeter.
    Write a function:
    class Solution { public int solution(int[] A); }
    that, given a zero-indexed array A of N integers, returns the maximum perimeter of any triangle in this array. The function should return −1 if there are no triangles.
    For example, given:
    A[0] = 10
    A[1] = 2
    A[2] = 5
    A[3] = 1
    A[4] = 8
    A[5] = 20
    the function should return 23, as explained above.
    Given array A such that:
    A[0] = 5
    A[1] = 10
    A[2] = 18
    A[3] = 7
    A[4] = 8
    A[5] = 3
    the function should return 25: the triangle with the maximum perimeter is (1, 3, 4).
    While for an array A:
    A[0] = 10
    A[1] = 20
    A[2] = 30
    the function should return −1, as it is impossible to create a triangle.
    Assume that:
    N is an integer within the range [0..100,000];
    each element of array A is an integer within the range [1..100,000,000].
    Complexity:
    expected worst-case time complexity is O(N*log(N));
    expected worst-case space complexity is O(1), beyond input storage (not counting the storage required for input arguments).
    Elements of input arrays can be modified.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,619
    Thanks
    45
    Thanked 1,958 Times in 1,932 Posts

    Default Re: Java Urgent Help

    I have a java question
    Where is your java code? What specific questions do you have about your program?
    Be sure to wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Urgent Help

    All I have is the question above with no other guidance. Do you think you could kindly form a rough code. Thank you

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,619
    Thanks
    45
    Thanked 1,958 Times in 1,932 Posts

    Default Re: Java Urgent Help

    Sorry, I don't write code for students.
    What have you got so far? Where are you having problems?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Urgent Help

    That's a shame because I am not a Student. I am helping my brother out whose going for a finance job and they have asked for him to do some code in java which is pointless for him as this is very IT technical.

  6. #6
    Member GoodbyeWorld's Avatar
    Join Date
    Jul 2012
    Location
    Hidden command post deep within the bowels of a hidden bunker somewhere under a nondescrip building
    Posts
    150
    My Mood
    Cheerful
    Thanks
    11
    Thanked 25 Times in 25 Posts

    Default Re: Java Urgent Help

    This thread has been cross posted here:

    Urgent - Please help to form code

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting


  7. #7
    Member
    Join Date
    Mar 2012
    Location
    United States
    Posts
    109
    My Mood
    Inspired
    Thanks
    1
    Thanked 32 Times in 30 Posts

    Default Re: Java Urgent Help

    So...do you or your brother have any experience with java?
    Also, regarding this bit:
    A[P] + A[Q] > A[R],
    A[Q] + A[R] > A[P],
    A[R] + A[P] > A[Q].
    The first rule is the only relevant one as the other two would be true by nature of 0 ≤ P < Q < R < N. One approach would be to sort array high to low, check the first 3 integers against the rules then print perimeter if they pass or move one index over. (If A[0],A[1],A[2] don't work then try A[1],A[2],A[3])


    GoodbyeWorld, that is not cross posting, just creating duplicate threads. If they posted the same thing on another forum (not jpf) altogether then that would be cross posting.

Similar Threads

  1. How do you do this in java?( This is urgent )
    By cbplayer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 15th, 2013, 01:16 AM
  2. How do you do this in java?( This is urgent )
    By cbplayer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 14th, 2013, 09:16 PM
  3. [URGENT]Need some Java help...
    By RePT in forum Paid Java Projects
    Replies: 0
    Last Post: July 5th, 2012, 07:03 AM
  4. Need Urgent Help for Java assignment..
    By SamanthaBenny93 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: May 22nd, 2012, 08:25 AM
  5. Need urgent help regarding java word wrap function.. URGENT
    By coldice in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 16th, 2011, 05:43 AM