Showing posts with label DataStructures. Show all posts
Showing posts with label DataStructures. Show all posts

02 November 2019

Tricky Questions

In Data Structures and Design Patterns, though there several questions being asked in interviews for senior developer positions, there are always some tricky and ever green questions which can only answered by developer if he has through knowledge on subject. Such kind of questions are listed here with their respective answers and time / space complexity required for it. Java is considered as language for coding as i am good at it. These tricky questions are accessible for only smart people who breaks the password and access the data. Happy Hacking!!

Enter password and click on show button

07 June 2017

How to reverse a linked list

Iterative:

Logic for this would be:
Have three nodes i.e previousNode,currentNode and nextNode
When currentNode is starting node, then previousNode will be null
Assign currentNode.next to previousNode to reverse the link.
In each iteration move currentNode and previousNode by  1 node.


public static Node reverseLinkedList(Node currentNode)

 {
// For first node, previousNode will be null
  Node previousNode=null;
  Node nextNode;
  while(currentNode!=null)
  {
   nextNode=currentNode.next;
  // reversing the link
   currentNode.next=previousNode;
  // moving currentNode and previousNode by 1 node
   previousNode=currentNode;
   currentNode=nextNode;
  }
  return previousNode;
 }