experiments.with.fb
BAN USER- 3 Answers Determine if duplicates exist in a string
Hi everyone, the solution for this on page 172 explains how to use a boolean array for this, with the assumption that we are dealing with ASCII characters. Why is the size of the array 256 when the set of ASCII values ranges only from 0 -127 ? Thanks for any help!
- experiments.with.fb January 28, 2015| Flag | PURGE
Written quickly before running to work, I realise there are checks I need to add. WIll add soon.
public class LLPairSwapFB {
public static void main(String[] args) {
LLNode p1, p2, p3, px, head;
LLNode n1 = new LLNode('A');
LLNode n2 = new LLNode('B');
LLNode n3 = new LLNode('C');
LLNode n4 = new LLNode('D');
n1.setNext(n2);
n2.setNext(n3);
n3.setNext(n4);
head = n2; //new head always n2?
p1 = n1;
p2 = p1.getNext();
p3 = p1.getNext().getNext();
px=null;
while(true){
p2.setNext(p1);
p1.setNext(p3);
if(px!=null)
px.setNext(p2);
else
px = p1;
if(p3!=null){
p1 = p3;
p2 = p3.getNext();
p3 = p3.getNext().getNext();
}
if(p1.getNext() == null){
break;
}
}
while(head!=null){
System.out.print(head.getData() + "->");
head = head.getNext();
}
System.out.print("null");
}
}
You are not alone. But here is what you could do. First of all, just know that you CAN solve the problem in front of you and just focus on the problem, and not your anxiety.
Next, get 2-3 friends to do "mock" interviews with you on the phone. Share a google doc, and write code together.
Do this a few times and it will help.
Thank You!
- experiments.with.fb January 31, 2015
Cleaned up to accept elements from command line, handle the case where there are 0 and 1 elements; and odd and even numbers of elements. The class LLNode is a simple java class with a data and a next field.
- experiments.with.fb April 25, 2015