Anil Singh
BAN USER
We can use combination of HashMap and customized Stack.
Stack here should maintained in such a way that we should see LFU object as peek,
and in case memory is full remove object from map same as peek of stack.
I always disagree with solutions coming out of naive iterations !!!
This can be solved by using Binary Search.
Perform a binary search for SUM - arr[i] in array.
Time complexity is O(n) here.
- Anil Singh April 20, 2013How come time coplexuty is O(n) here ?
- Anil Singh April 20, 2013public class ArrayMaxSum {
/**
* @param args
*/
public static void main(String[] args) {
String string = "1,2,-10,3,4,-20,5,6,4,-50,9,0,-1";
String[] numbers = string.split(",");
LinkedList<String> lst = new LinkedList<String>();
LinkedList<String> tmp = new LinkedList<String>();
int max_so_far = 0;
int max_ending_here = 0;
for (int i = 0; i < numbers.length-1; i++)
{
max_ending_here = max_ending_here + Integer.parseInt(numbers[i]);
lst.add(numbers[i]);
if (max_ending_here < 0)
{
max_ending_here = 0;
lst.clear();
}
if (max_ending_here > max_so_far)
{
tmp.clear();
max_so_far = max_ending_here;
tmp.addAll(lst);
}
}
for(String str : tmp)
{
System.out.print(str+", ");
}
System.out.print(" = "+max_so_far);
}
}
After for loop firstKth points to first Kth element in list.
After completion of while loop lastKth will point to Kth from last in list.
Repjimbtam, Backend Developer at ASAPInfosystemsPvtLtd
I was extremely into photography for a number of years.My father was also interested in photography, so I was ...
Reppamulapaya2, Area Sales Manager at Alcatel Lucent
Jorie , a Customer services manager with more than 6 years' experience working is responsible for managing the relationships between an ...
Repzhenhsiungz, Android test engineer at AppPerfect
I am a financial planner . I help individuals and corporations meet their long-term financial objectives. I enjoy spending my spare ...
Repirmajrichh, Junior programmer at AppNexus
I am Irma, seeking the position of a Historical Researcher at Littler’s where my expertise can be utilized to ...
Repmarkhlee8, Research Scientist at Bank of America
I am a cooking Instructor in New York USA, I Have a degree from the prestigious Culinary Arts Institute of ...
RepLauraJOles, Android Engineer at A9
Hi i am Laura.I live in Us from my childhood and i love my country.My father he is ...
RepI am Risk managers that advise organizations on any potential risks to the profitability, safety, security or existence of the ...
RepTinaaJohn, Cloud Support Associate at AMD
Hi,Everyone.I am an art teacher at Woodson Institute.Foster and encourage critical thinking and analysis about art and ...
Repvickiwgerber, Member Technical Staff at Boomerang Commerce
I am Vicki From San Antonio USA, I am working as an Interior decorator in Golden Joy company. I have ...
Repshanitajjana, +27655765355 SSD MONEY CLEANING CHEMICAL +27655765355 BLACK MONEY IN JOHANNESBURG, OMAN, SAUDI ARABIA, SUDAN, Somalia ,Zimbabwe Botswana at 247quickbookshelp
Hi I am Shanita from San Bernardino USA. I am working as a manager in flore company. I am outgoing ...
Repverarfurman, Problem Setter at Cerberus Capital
I am Vera from Bullard USA, I am working as a Violin repairer in a Handyman company. My interest in ...
Repnancyhfloress, Computer Scientist at AMD
Hey there, I’m Nancy. I’m a small business owner living in Sunrise, FL 33323. I am a fan ...
Reprajanadeep17, Android Engineer at 247quickbookshelp
I am a Special education teacher who adapts general education lessons and teaches various subjects to students with mild to ...
RepRoseReynolds, Analyst at 8x8
Hi everyone I am Lilla from the UK.I am passionate about two things, gym and book lover.Last topic ...
Repjessicajbunting, Aghori Mahakal Tantrik at ABC TECH SUPPORT
Hi I am Jessica, from Houston USA. I am working as a manager in Incredible Universe company. I enjoy additional ...
Repnatetouche, Applications Developer at Alcatel Lucent
My name is NateTouche . I currently live in Seattle . One desire that has always been a constant since As a ...
Repkellydbrown23, Jr. Software Engineer at Auto NInja
I live in College Park USA with my family, and my current job is clerk in Luria’s company. I ...
Repannaharricks, Computer Scientist at ABC TECH SUPPORT
Hi, I am a Social worker to help people handle everyday life problems. I also assist people who have issues ...
RepI am Rasha , C/C++ certified Computer Programmer with expert-level competency in JavaScript, HTML and JSP and more than 6 ...
Repstacyrdavid, Associate at Abs india pvt. ltd.
Hi, I am Stacy working as a Cashier in Dollar store the US. I work for Us government to Collect ...
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 ...
Repashleymbosse, Associate at Accenture
I am an enthusiastic, hard-working and disciplined Catering Assistant with excellent track-record in working in the food industry. I am ...
Repelisahbuff, Apple Phone Number available 24/7 for our Customers at Altera
I have previous work experience in a customer focused environment. I like to Enjoy my Free Time Playing football.I ...
Repthonylermat, OOPS Experienced at 247quickbookshelp
I have been assigned based on the successful candidate's level of training and experience but will include types of ...
RepHi, I am Anne from Portsmouth, USA. I have been working as a freelance digital illustrator specialized in 3D character ...
Repstephiegoblin, Research Scientist at Aristocrat Gaming
Je suis Stephie, une rédactrice associée très créative, organisée et expérimentée, à la recherche d'un poste de direction dans ...
RepCarlERhodes, Cloud Support Associate at Baidu
I am an Engineering manager in Mosier USA. I am a freelance events coordinator and a lifetime entrepreneur. I want ...
RepGiannaDavid, Author at The times
I am an Author, I have a passion for reading and creative writing and attend many workshops and conventions surrounding ...
Repvictorcraigw, Animator at Chicago Mercantile Exchange
Hi, I am Victor working as a Speech Writer in the USA. Spoke at an academic conference about mantra for ...
Looks like an excellent solution driven by mathematics !!!
- Anil Singh January 16, 2014