futurnist
BAN USER
This solution is wrong for following test case:
int[] a = {100};
int[] b = {10, 20};
int[] c = {1, 10000};
It'll report a, b, c to be 100, 10 and 1 respectively while the optimal one is 100, 20, 1.
This is because following statement is wrong:
"If you think about, you will conclude that you must increment the element with minimum value between i, j and k."
import java.util.Arrays;
public class Tmp {
/**
* @param args
*/
public static void main(String[] args) {
int[] a = {100};
int[] b = {10, 20};
int[] c = {1, 10000};
int[] d = minizeDistance(a, b, c);
System.out.println(Arrays.toString(d));
}
public static int[] minizeDistance(int[] a, int[] b, int[] c) {
int[] minIndexes = null;
Integer minVal = null;
int i=0, j=0, k=0;
while (true) {
int curMin = Math.max(a[i] - b[j],
Math.max(b[j] - c[k], c[k] - a[i]));
if (minVal == null || curMin < minVal) {
minVal = curMin;
minIndexes = new int[]{i, j, k};
}
boolean canIncI = i != a.length-1;
boolean canIncJ = j != b.length-1;
boolean canIncK = k != c.length-1;
if (!canIncI && !canIncJ && !canIncK)
break;
if (canIncI && (!canIncJ || a[i] < b[j])
&& (!canIncK || a[i] < c[k]))
++i;
else if (canIncJ && (!canIncK || b[j] < c[k]))
++j;
else
++k;
}
System.out.println("minVal = " + minVal);
return minIndexes;
}
}
bytestorm's idea is correct. However there's no need to implement full Finite Automata due to the nature of this problem. Simply search for each character of pattern in the given filename and return true only if pattern can be exhausted.
Code in Java:
String filename = ...
String pattern = ...
int p1 = 0, p2 = 0;
while(p1 >= 0 && p2 < pattern.length){
char c = pattern.charAt(p2);
int tmp = filename.indexOf(c, p1);
if(tmp < 0){
return false;
}
p1 = tmp + 1;
p2 ++;
}
return true;
Repaaronfreunda, Human resources coordinator at Prestiga-Biz
Aaron , My work is to facilitate daily HR functions like track of employees records and supporting the interview process. I ...
RepRobin Strain, Consultant
I am from New york. I am 26 year old. I work in a Central Hardware as a Worker compensation ...
Repevelynleary0, Consultant at Arista Networks
Hi, I am Evelyn from Los Angeles, USA. I have been a Marketing Manager in Veramons Digital Company from last ...
RepTristaRJohn, Reverse Engineering and System Developer at BT
I am an Ophthalmic medical assistant in bluefield USA, I assist in retinal exams and procedures. Referred patients to outside ...
Repcharlieesandobal, Security Analyst at ADP
I am Charliee , a dedicated security professional at Monsource for the last 6 years managing security teams and corporate environments ...
Repjennifertkramer, AT&T Customer service email at ADP
I had a dream to open my own Restaurant in FL. and i came true all dream with my hard ...
Repkayegoinsk, Cloud Support Associate at ABC TECH SUPPORT
Hello, I'm Kim Starns. I work as a Telephone service representative at the respected Sholl's Colonial Cafeteria. Part ...
Repsusancmeans, Apple Phone Number available 24/7 for our Customers at Absolute Softech Ltd
I am Susan from Bronx, I am working as a Business management analyst in Brendle's company. I Have a ...
RepI graduated from College with a master’s degree in arthrogryposis. After graduation I am working as a manager in ...
Repronalddavis284, Accountant at ADP
As you may be able to infer from my professional background, I have a strong interest in mathematics and the ...
Repamysamson688, Accountant
Hi, I am an art teacher, good in all areas of art history, from ancient art through to contemporary art ...
Repivaharvie, Production Engineer at BMO Harris Bank
Je suis Iva, professeur de musique et compositeur avec plus de 6 ans d'expérience avec une connaissance approfondie de ...
Reppaulinedsisk, Testing / Quality Assurance at Cloudmere, Inc.
I want to become a successful professional in a highly competitive technological world where performance is rewarded with exciting new ...
RepSaraLopez, abc at ADP
Experienced in all aspects of business formation, operation, finance, and management. Visionary product developer with deep education in research and ...
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 ...
Rephazelwlson80, abc at A9
I am a skilled civil engineer with many years of experience in a variety of engineering aspects. There are a ...
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 ...
Repemilinarula, Dev Lead at ABC TECH SUPPORT
Hi, i've been spotting for about 4 years.Teamwork: works well as a member of a team, pitches in ...
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 ...
Repellenabeaudry4, Analyst at Boomerang Commerce
I'm a 23 year-old blogger, make-up junkie and follower of Hinduism.I love Reading because it brings happiness for ...
Repmartinskrull, Analyst at A9
Hi everyone, I am from new york,USA. I currently work in the Affiliate Marketing industry. I love all things ...
Repcolettehenna, OOPS Freshers at Bosch
I am Colette , policy analyst at Sunflower Market , with 3 years of experience building and maintaining relationships with elected officials ...
Repdianacloweryd, Developer Program Engineer at Accolite software
I am Diana from Reston USA . I work as an Agricultural and food science technician in Jumbo Sports. I help ...
RepAmberBrook, Animator at A9
Hi everyone, Done my master of arts in specialized journalism.Also an member of society of professional journalists since 2015 ...
RepPriscillaRYoung, Aghori Mahakal Tantrik at Absolute Softech Ltd
Hi, I am Priscilla from California. I am working as a Business management consultant in Quality Merchant Services company. I ...
Repaliciajdew, Integration Software Engineer at Absolute Softech Ltd
I have a strong base in marketing and I believe in focused strategies that bring brands to their relevant audiences ...
RepGretaHLopez, abc at ASAPInfosystemsPvtLtd
Hello, I am Greta and I am working as a GIS specialist who often works for state or local governments ...
Replarryehickl, Associate at ABC TECH SUPPORT
I am a blogger in the Geek system operator . As an editor with a strong background in english and hindi ...
RepHi, I am Anne from Portsmouth, USA. I have been working as a freelance digital illustrator specialized in 3D character ...
RepWandaScales, Applications Developer at Aspire Systems
I am a Medical writer in the Just For Feet company . I enjoy spells for making someone obsessed with you ...
RepGrimesOtto, Java Developer at Coupondesh
I am Grimes Agriculture inspector. I examine agriculture commodities and related operations . I like listening to music, painting, and reading ...
RepFanieGoode, Consultant at Achieve Internet
I am a Media Library Assistant that provides integrated support for two popular “Multi Language/ Multilingual/ Internationalization” plugins; WPML and ...
RepRhondaLillie, Android test engineer at AppNexus
I work as an General and operations manager at the Official All Star Café. presenting love stories, ghost stories. Currently ...
Repannavhedge4, AT&T Customer service email at ABC TECH SUPPORT
Hi everyone, I am from Worcester,USA. I currently work in the Argus Tapes & Records as Scientific illustrator . I love ...
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 ...
RepAnnetteFlynn, Android test engineer at ABC TECH SUPPORT
Hello I am a skill trainer. Master's Degree in Industrial and Organisational Psychology and 10 years of experience working ...
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 ...
input {1, 1, 2}
- futurnist May 21, 2012In your first iteration you set a[ a[0] ] which is a[1] to negative
In your second iteration you are referring to a[ a[1] ] which is a[ -1] which is an error.