tnmd
BAN USERCan someone please comment on this code? It seems to work, but I would like to know how efficient it is...
public static int findIndexK(int k, int[] a) {
int index = -1;
int fromLeft = tryFromLeft(k, a);
if (fromLeft == -1)
index = tryFromRight(k, a);
else
index = fromLeft;
return index;
}
public static int tryFromLeft(int k, int[] a) {
int res = -1;
for (int i = 0; i < a.length; i++){
if (a[i] > k) break;
if (a[i]==k) return i;
}
return res;
}
public static int tryFromRight(int k, int[] a) {
int res = -1;
for (int i = a.length - 1; i >= 0; i--){
if (a[i] < k) break;
if (a[i] == k) return i;
}
return res;
}
public static void main(String[] args) {
int[] a = { 4, 5, 6, 7, 8, 9, 1, 2, 3 };
int k = 0;
System.out.println(findIndexK(k, a));
}
- tnmd October 28, 2013I have never been on a technical interview, so please don't laugh at me... But how do I understand if I can use something already built-in in the language or whether I have to write everything from scratch?
For example, in this situation, why can't we just write something like this:
public boolean isMatch(String s1, String s2){
s1 = s1.replaceAll("\\*", "?");
Pattern p = Pattern.compile(s1);
Matcher m = p.matcher(s2);
return m.matches();
}
?
RepHello friends my name Neha Nanda from India Chandigarh city. Doing work in SEO line in Softsys company.
RepErmanStern, Applications Developer at ADP
I am Erman . I am metal finishing-, plating- and coating-machine operators operate and monitor equipment which finishes, plates and coats ...
Repsylviarashtons, Accountant at ASAPInfosystemsPvtLtd
I am a journalist. Outside the office, I enjoy additional writing time in a different genre of historical fiction. I ...
RepJanie Margreta, Android Engineer at Achieve Internet
JanieMargreta works as a plant operator, an employee who supervises the operation of an industrial plant. Where I have to ...
RepMy name Madhu Nanda from Himachal pardesh. I am a writter in English lectractrue.
RepPatriciaNRowe, Consultant at ADP
Hi i am a Freelance Writer and Social Media Manager who helps finance professionals and Fin-tech startups build an audience ...
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 ...
Repmelissamewingm, abc at ABC TECH SUPPORT
I am Melissa from Springdale. I function as an Auditing assistant in Bountiful Harvest Health Food Store. My solid interest ...
Repkarinkwalton, Backend Developer at Broadsoft
I am working as a Support clerk in an MVP Sports company. I love traveling and exploring facts about technology ...
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 ...
RepI am an energetic sales professional with a track record of consistently increasing sales revenue in a competitive market. Contract ...
}
- tnmd October 29, 2013