EminGuliyev1987
BAN USERclass Node{
public Node right;
public Node left;
}
public class LongestPath {
private static int longestPath=0;
public int height(Node root){
if (root == null){
return 0;
}
int leftHeight = height(root.left);
int rightHeight = height(root.right);
longestPath = Math.max(longestPath, leftHeight+rightHeight+1);
return Math.max(leftHeight,rightHeight) + 1;
}
}
Use find-union structure
- EminGuliyev1987 August 07, 2016public class RepeatedInteger {
public static void main(String[] args) {
int[] arr = {2 ,1, 3,2,4};
int n=5;
int result=0;
for (int i=0; i<n;i++){
result^=arr[i];
}
for (int i=1; i<n; i++){
result^=i;
}
System.out.println(result);
}
}
Works right for all inputs tested
package strings;
import java.util.ArrayList;
/**
* Created by Emin Guliyev on 24/08/2015.
*/
//http://www.careercup.com/question?id=5717301963784192
public class BashBrace {
private int i=0;
public String s;
public BashBrace(String s) {
this.s = "(" + s + ")";
}
public ArrayList<String> getStringArray() {
ArrayList<String> result = new ArrayList<>();
ArrayList<String> temp;
if (s.charAt(i) == '(') {
i++;
while (s.charAt(i-1) != ')') {
temp = getStringArray();
result.addAll(temp);
i++;// skip "," or ")"
}
if (i == s.length()) {
return result;
}
result = getCartesianProductStringArray(result);
} else {
String literal = "";
while (i < s.length() && s.charAt(i) >= 'a' && s.charAt(i) <= 'z') {
literal += s.charAt(i);
i++;
}
result.add(literal);
result = getCartesianProductStringArray(result);
}
return result;
}
private ArrayList<String> getCartesianProductStringArray(ArrayList<String> result) {
ArrayList<String> temp;
while (i < s.length() && s.charAt(i) != ',' && s.charAt(i) != ')') {
temp = getStringArray();
result = cartesianProduct(result, temp);
}
return result;
}
private ArrayList<String> cartesianProduct(ArrayList<String> listA, ArrayList<String> listB) {
ArrayList<String> result = new ArrayList<>();
for (String a: listA) {
for (String b : listB) {
result.add(a+b);
}
}
return result;
}
public static void main(String[] args) {
BashBrace bashBrace = new BashBrace("((a,b)o(m,n)p,b)");
for (String item : bashBrace.getStringArray()){
System.out.println(item);
}
}
}
RepSuzaneVenable, Applications Developer at 247quickbookshelp
I am an employment manager typically in charge of planning the hiring processes, setting guidelines and timelines, and establishing budgets ...
RepCliftonMalone, Android Engineer at ABC TECH SUPPORT
Hello, I am a Seo Analyst with 5 years of experience in helping large ecommerce websites reach higher organic positions ...
RepAmaraPerez, Android Engineer at Allegient
I am an outgoing and motivated flight attendant with a strong customer-oriented approach and excellent communication skills.I am always ...
Replloismyers, Grounds maintenance worker at Eagle Hardware & Garden
I am a ground maintenance worker who typically mows grass, edges, and fertilises lawns. I also weed and mulch landscape ...
Hey guys, now I am SDE II in Amazon. I was preparing in the same way as I did for Microsoft. In addition I repeated Distributed Systems lectures, also did 46 pages from Amazon interview problems from this site. Last 10 days also did mock interviews. All preparation took 30 days. So for first big interview (Microsoft, 10 month before) I did 3 month preparation but for second one (Amazon) I did only 1 month preparation. This method works, guys. Good luck to all of us.
- EminGuliyev1987 September 18, 2016