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.


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

Results 1 to 2 of 2

Thread: Urgent - Please help to form code

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

    Question Urgent - Please help to form code

    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].
    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
    Member GoodbyeWorld's Avatar
    Join Date
    Jul 2012
    Hidden command post deep within the bowels of a hidden bunker somewhere under a nondescrip building
    My Mood
    Thanked 25 Times in 25 Posts

    Default Re: Urgent - Please help to form code

    This thread has been cross posted here:


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

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting

Similar Threads

  1. Need help with my java code! [URGENT]
    By proera92 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 9th, 2013, 07:54 PM
  2. URGENT: Please help me with my code!
    By Snoopchicken in forum What's Wrong With My Code?
    Replies: 12
    Last Post: December 18th, 2012, 06:21 PM
  3. Need help with this code urgent please, i appreciate it.
    By joelmeler in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 30th, 2011, 09:11 PM
  4. URGENT Need help with code for billing
    By ab3lr in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 13th, 2011, 11:44 AM
  5. Urgent code needed
    By subhvi in forum AWT / Java Swing
    Replies: 4
    Last Post: August 27th, 2009, 12:55 AM