sethuraj.32
BAN USER
We can use divide and conquer approach.
Let h[] be the array and kth element be the minimum element in h[] from index i to j
max_area = max(max_area(i, k-1), max_area(k+1, j), h[k]*(j-i))
i will be set to 0 and j will be set to array length initially
Hash the array.
Iterate the array and check if x-a[i] exists in the hash.
Corner case is if x=4 and a[i]=2 and no other two is there in the array.
I think this code will work
public class FindCombi {
public static void main(String[] args) {
int s = 5;
int n = 3;
helper(n, s);
}
private static void helper(int n, int s) {
int[] a = new int[n];
finAllCombi(a, n, s, 0, 0);
}
private static void finAllCombi(int[] a, int n, int s, int sum, int i) {
if(i+1==n) {
a[i] = s - sum;
print(a);
return;
}
for(int m=0; m<=s-sum; m++) {
a[i] = m;
finAllCombi(a, n, s, sum+m, i+1);
}
}
private static void print(int[] a) {
String st = "";
for(int i=0; i<a.length; i++) {
st = st + a[i] ;
if(i+1 != a.length) {
st = st + "+";
}
}
System.out.println(st);
}
}
Replcarton941, Android test engineer at 8x8
My name is Lilly. I grew up in Somerset and currently live in the US. One desire that has always ...
Repjuanitajboon, Applications Developer at 247quickbookshelp
Hi everyone, I am from Pelham. I currently work in the Hechinger as Cashier.I like to do creative things ...
RepJe suis Hudson Will des États-Unis. Je travaille comme technicien dans une entreprise Éco Vannes. J'analyse et vérifie tous ...
Repjacksssones433, Apple Phone Number available 24/7 for our Customers at A9
Proficient and creative WordPress developer with a strong history in website management and development. Experienced in SEO and PPC campaign ...
Replyndaander9, Analyst at A9
My name is Anderson and I am a 24 years old trader born and currently working in New York, USA ...
RepRobertBaumbach, Administrative Manager at Meridian Mechanical Services
Repjacksabjohne, Accountant at ABC TECH SUPPORT
Michael is a Biological Technician with 4 years of experience monitoring, characterizing, and quantifying riverine processes and habitat in the ...
RepI am Rasha , C/C++ certified Computer Programmer with expert-level competency in JavaScript, HTML and JSP and more than 6 ...
Repshawt146, Applications Developer at ADP
I love Exploring and photography. I want to fill my life with happiness and beautiful mammaries. I also like to ...
Repjosephcday6, Android Engineer at Absolute Softech Ltd
I am SEO Executive in Elek-Tek company. I live in Morgantown USA. I won’t write any details about Best ...
Repman254183, Project Leader at GoDaddy
I am working as Human Resources Associates, and my duties are for obtaining, recording, and interpreting human resources information within ...
Repbrakpeter2, AT&T Customer service email at Absolute Softech Ltd
My Profession Is photography for a number of years.My Friends were interested in photography, so I was always exposed ...
RepSilvia Devidson, maintenence engineer at Live Nation
Silvia Devidson working as a mechanical piping estimator performs process piping takeoffs from engineered drawings at various levels of design ...
RepAvikaEthan, Data Engineer at Adjetter Media Network Pvt Ltd.
Avika Ethan has five years of experience collecting physical and biological data in California streams and rivers. In the field ...
- sethuraj.32 November 04, 2012