5






Given an array of ints length 3, figure out which is larger between the first and last elements in the array, and set all the other elements to be that value. Return the changed array. 
maxEnd3({1, 2, 3}) → {3, 3, 3}
maxEnd3({11, 5, 9}) → {11, 11, 11}
maxEnd3({2, 11, 3}) → {3, 3, 3}

Solution:

public int[] maxEnd3(int[] nums) {
  int max = Math.max(nums[0], nums[2]);
  nums[0] = max;
  nums[1] = max;
  nums[2] = max;
  return nums;

  // Solution notes: you could write if-logic to figure out
  // which element is the biggest, but here we use Math.max()
  // to solve that part nicely.
}

OR


public int[] maxEnd3(int[] nums) {
  int[] maxVal=new int[3];
  maxVal[0]=nums[0];
  if(nums[2] >= maxVal[0])
  maxVal[0] = nums[2];
  maxVal[1] = maxVal[0];
  maxVal[2] = maxVal[0];
  return maxVal;
}

Post a Comment

  1. Many specialized SEO tools can help you determine the popularity and the competitiveness of your possible keywords and can help improve your search engine ranking particularly in Google.Niche Blog Comments Available

    ReplyDelete
  2. Your work is very good and I appreciate you and hopping for some more informative posts. Thank you for sharing great information to us. SEO Services

    ReplyDelete
  3. "Well explained! I’ve recently started using image and video submissions for backlinks, and the results are impressive. What are your thoughts on this approach?" Rankspheres

    ReplyDelete
  4. A diversified backlink strategy using articles, blog comments, and profiles is exactly what Google prefers — and Embossitworld provides all three. what is blog commenting

    ReplyDelete
  5. Off page SEO depends heavily on backlinks, and blog comments are one of the most effective ways to create diversity. This service looks like a genuine solution that focuses on manual work and quality backlinks. Safe SEO practices like these are exactly what websites need today. High Authority Backlinks

    ReplyDelete

 
Top