Oracle Interview Question for Software Engineer / Developers


Country: -
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
0
of 0 vote

public static LNode add1(LNode l1, LNode l2){
		LNode result = null;
		int size1 = size(l1);
		int size2 = size(l2);
		int currentDigit = Math.max(size1,size2);
		boolean carrier = false;
		while(l1 != null && l2 != null)
		{	
			int sum = 0;
			if(currentDigit <= size1){
				sum += l1.value;
				l1 = l1.next;
			}
			if(currentDigit <= size2){
				sum += l2.value;
				l2 = l2.next;
			}
			
			currentDigit--;
			
			if(carrier){
				sum += 1;
			}
			if(sum >= 10){
				carrier =true;
			}else{
				carrier = false;
			}
			result = append(result,sum%10);
		}
		if(carrier)
		{
			result = append(result,1);
		}
		return result;
			
	}
	public static int size(LNode head){
		if( head == null) return 0;
		
		LNode tmp = head;
		int counter = 0;
		while(tmp != null){
			counter++;
			tmp = tmp.next;
		}
		return counter;
	}

- .·´¯`·.´¯`·.¸¸.·´¯`·.¸><(((º> January 28, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hi,
I just want to know why you have added this condition

if(carrier)	{
	sum += 1;
}

and also we shouldn't validate max sum as 18 as it can be one digit as 9 and 9 so shouldn't we consider the sum >= 18 instead of 10.

- Vaibhavs February 16, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1, reverse the two linkedlist,
2, add them to one of the linkedlist,
3, reverse this linkedlist.

- Yi Wang March 03, 2014 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More