Sum it up problem

why i am getting two test cases wrong
link to my code: https://ide.codingblocks.com/s/142827

see when we retrieve element from hashmap they dont come in the order in which we have added them…your logic is fine but the order was not correct…so here is a soln…you could print the string in the base case only…

import java.util.*;
public class Main {
   static HashMap<String,Integer> h=new HashMap<>();
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++)
		{
			a[i]=sc.nextInt();
		}
      int s=sc.nextInt();
      Arrays.sort(a);
      sum(a,s,0,"");
    //   for(String i:h.keySet())
    //   {
    // 	  System.out.println(i);
    //   }
    		  
	}
	public static void sum(int a[],int s,int i,String ans)
	{
		if(s==0)
		{
		   if(!h.containsKey(ans)){
               h.put(ans,1);
               System.out.println(ans);
           }
		    
		}
		if(i==a.length||s<0)
			return;
			   sum(a,s-a[i],i+1,ans+a[i]+" ");
			   sum(a,s,i+1,ans);
			   
	}
}

thank u so much got it.