Arrange all even number in ascending and arrange all odd number in descending and concatenate them



Problem to arrange all even number in ascending and arrange all odd number in descending and concatenate them.



Example-1:


Input    : n = [ 1, 2, 3, 4, 5]
Output   : [2,4,5,3,1]    


Example-2:


Input    : n = [ 6, 7, 8, 9]
Output   : [6,8,9,7]    







Solution




import java.util.*;

public class Main
{
    public static void main(String[] args) 
    {
         String s1 = "BAT";

         String s2 = "ABT";

         if(s1.length() != s2.length())
         {
              System.out.print("Not a Anagram");
         }

         else
         {
              char ch_s1[] = s1.toCharArray();

              char ch_s2[] = s2.toCharArray();

              Arrays.sort(ch_s1);

              Arrays.sort(ch_s2);

              for (int i = 0; i < ch_s2.length; i++) 
              {
                    if(i == ch_s2.length-1 && ch_s1[i] == ch_s2[i])
                    {
                        System.out.print("Anagram");
                    }

                    if(ch_s1[i] != ch_s2[i])
                    {
                       System.out.print("Not a Anagram");
                       break;
                    }
              }
          }
    }
}
n = [ 1, 2, 3, 4, 5]

l = []

k = []

for i in range(len(n)):

    if(n[i] % 2 == 0):

        l.append(n[i])

    else:

        k.append(n[i])

m = l+k[::-1]

print(m)



Output



[2, 4, 5, 3, 1]