Skip to content

Instantly share code, notes, and snippets.

@pruthvi6767
Created August 21, 2017 05:23
Show Gist options
  • Save pruthvi6767/8fbedeb7b784b6305bf0d11af92db714 to your computer and use it in GitHub Desktop.
Save pruthvi6767/8fbedeb7b784b6305bf0d11af92db714 to your computer and use it in GitHub Desktop.
Fortinet_QA
1. Objective: Algorithm:
Reverses a single list. Need answer with Java code
The Node of the single list as the following:
class Node{
Node next;
int value;
}
Test Cases:
1. null =null (the List is null)
2. 1->null =1->null (the list has only one Node with value 1)
public Node reverseList(Node head){
// Iterative Solution using 3 pointers
// Runtime: O(n)
// Space Complexity: O(1)
if (head == null && head.next == null) {
return head;
}
Node prev = null;
Node curr = head;
Node next = null;
while (curr != null) {
next = curr.next;
curr.next = prev; // changes arrow direction
prev = curr;
curr = next;
}
return prev;
}
// JUnit test cases
@Before
LinkedList list = new LinkedList();//Initialized with head as null
Node head = list.getHead();
@Test // Empty list with head null
public void testEmptyList(){
assertNull("List is empty", list.reverseList(head));
}
//After list is populated
@Test
public void testList(){
list.insertNode(1);
//list.inserNode(2); -->(inserts at head if head is null else at tail)
//list.insertNode(3);
assertNotSame("list is reversed", head, list.reverseNode(head));
}
--------------------------------------------------------------------------------------------------------------------------------------
2. Objective: I hope this is a good way you let us know you have mastered the selected design pattern, you know where to use it
and how to use it. So firstly provide a scenario/ problem in a few words, then provide the resolution in the code to resolve this problem.
Scenario: Initializing the DataSource with single instance using singleton pattern.
class Singleton {
private Singleton() {}
public String str;
private static Singleton instance = null;
public static Singleton getSingleInstance() {
if (instance == null) {
instance = new Singleton();
}
return instance;
}
}
Additional Q&A:
What is Session in Hibernate?
-The session opens a single database connection when it is created, and holds onto it until the session is closed.
Every object that is loaded by Hibernate from the database is associated with the session, allowing Hibernate to
automatically persist objects that are modified, and allowing Hibernate to implement functionality such as lazy-loading.
@pruthvi6767
Copy link
Author

gist for q/a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment