Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9180733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:07:26+00:00 2026-06-17T18:07:26+00:00

Given an array which is having elements which are in increasing order till a

  • 0

Given an array which is having elements which are in increasing order till a max value and then numbers in decreasing order.

Eg. int a[] = { 10, 12, 14, 16, 15, 13, 11}.

How can this array be sorted efficiently?

The array needs to be sorted in-place.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:07:27+00:00Added an answer on June 17, 2026 at 6:07 pm

    My solution:

    1. Take 2 pointers start of array and end of array.

    2. Into result array write a min(or max if you need sort in descending) value from both pointers, and shift
      pointer to 1 position (start pointer +1 position and end pointer -1
      position

    3. Repeat till start pointer will be placed after end pointer.

    Complexity of solution is O(N).
    Required memory is O(N)

    Pseudocode:

    function Sort(a)
    {
      startPointer = 0;
      endPointer = a.length-1;
      result = new Array of size a.length
      while (startPointer <= endPointer)
      {
        var newValue;
        if (a[startPointer] < a[endPointer])
        {
          newValue = a[startPointer];
          startPointer +1
        }
        else
        {
          newValue = a[endPointer];
          endPointer -1
        }
        result[a.length - startPointer - endPointer] = newValue;
      }
    
      return result;
    }
    

    Solution for updated question:

    As solution usde partil sorting of first part of array.

    Pointers on (10 and 11)
    {10, 12, 14, 16, 15, 13, 11}

    Pointers on (12 and 11)
    Swap 12 and 11
    {10, 11, 14, 16, 15, 13, 12}

    Pointers on (14 and 12)
    Swap 14 and 12
    {10, 11, 12, 16, 15, 13, 14} // Move pointer from 14 to 13 a it lesser.

    Now we have sorted {10, 11, 12} and sub problem for {16, 15, 13, 14} (N for sub problem decreased twicely)

    Complexity for this algorithm is: O(N) + (N/2) + O(N/4) + … totally is O(N)

    Image for better illustration:

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a Algorithm question, in which numbers are been given from 1
I want to mark all maxima along a given axis of an array (which
Hi need help getting repeated value from give array,below is the code which im
Given an Array A of n subArrays Sn, how can I select the Array
Given a function which returns an array; function return_me_an_array() { return array('my_value'); } How
Given an infinite length sorted array having both positive and negative integers. Find an
I have a search form regarding property search having some elements on which search
Given 3 variables (homeNumber,mobileNumber and workNumber), which can be null, but atleast one of
Given 2 2x2 Numpy arrays, each element having a value between 0 and 1,
Given two arrays, how to find the maximum element which is common to both

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.