Oracle Interview Question for Software Engineer / Developers

Country: -
Interview Type: In-Person

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

A recursive implementation, call reverseList(head,null) to reverse the list:

``````public static<T> ListNode<T> reverseList(ListNode<T> head, ListNode<T> prev){

// the head became the previous element and temp became the new head
}``````

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

``````public static LNode reverse(LNode head){

}else{
LNode current = previus.next;
LNode next = current.next;
previus.next = null;
while(next != null){
current.next = previus;
previus = current;
current = next;
next = next.next;
}

current.next = previus;
}
}``````

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

``````/* Function to reverse the linked list */
{
struct node* prev   = NULL;
struct node* next;
while (current != NULL)
{
next  = current->next;
current->next = prev;
prev = current;
current = next;
}
}``````

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

``````void recursiveReverse(struct node** head_ref)
{
struct node* first;
struct node* rest;

/* empty list */
return;

/* suppose first = {1, 2, 3}, rest = {2, 3} */
rest  = first->next;

/* List has only one node */
if (rest == NULL)
return;

/* reverse the rest list and put the first element at the end */
recursiveReverse(&rest);
first->next->next  = first;

/* tricky step -- see the diagram */
first->next  = NULL;

/* fix the head pointer */
}``````

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

``````public void setNext(ListNode node) {
this.node = node;
}
public void getNext() {
return this.next;
}

ListNode temp = null,nextNode = null;
}
return temp;
}``````

Time complexity:O(n) Space Complexity:O(1)

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

``````private static Node reverse(Node node) {
if (node == null || node.next == null) {
return node;
}
node.next.next = node;
node.next = null;
}``````

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.

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.