https://ide.codingblocks.com/s/163101 This is my code. I am getting permutations in my answer and also I dont know how to print answer lexicographically
How to avoid permutations and how to print answer lexicographically
to see the changes which i have made
pls see this symbol after the line “—>”
import java.util.*;
public class Main {
public static void printt(int []arr,int t,String s,int ans,int in)
{
if(ans==t)
{
System.out.println(s);
return ;
}
for(int i=in;i<arr.length;i++) --->
{
ans+=arr[i];
if(ans<=t && (i == in || arr[i] != arr[i - 1])) --->
printt(arr,t,s+arr[i]+" ",ans,i+1); -->
ans=ans-arr[i];
}
}
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int n,t;
n=sc.nextInt();
int arr[]=new int[n];
for(int i=0;i<n;i++)
arr[i]=sc.nextInt();
Arrays.sort(arr);
t=sc.nextInt();
printt(arr,t,"",0,0); --->
}
}
hope this will help u
pls rate my work so that i can improve my work
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.