Skip to content

Commit

Permalink
Add DeleteMiddleElement, duplicateElements, find the kth to last node…
Browse files Browse the repository at this point in the history
… in a linkedlist
  • Loading branch information
sangaryousmane committed Feb 28, 2024
1 parent 757d054 commit 2a72d23
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/advance/crackingCodingInterview/ListNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package advance.crackingCodingInterview;public class ListNode {
}
2 changes: 2 additions & 0 deletions src/advance/crackingCodingInterview/Tests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package advance.crackingCodingInterview;public class Tests {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package advance.crackingCodingInterview.linkedList.palindromes;

import advance.crackingCodingInterview.ListNode;

import java.util.HashSet;
import java.util.Set;

public class DeleteDuplicates {

// TC and SC is: O(n)
public void deleteDup(ListNode node) {
Set<Integer> set=new HashSet<>();
ListNode previousNode=null;

while (node != null){
if (set.contains(node.data)){
previousNode.next = node.next;
}
else {
set.add(node.data);
previousNode = node;
}
node = node.next;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package advance.crackingCodingInterview.linkedList.general;public class DeleteMiddle {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package advance.crackingCodingInterview.linkedList.general;public class DetectLoopInLinkedList {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package advance.crackingCodingInterview.linkedList.general;public class KthToLast {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package advance.crackingCodingInterview;
// Check if the linked list is a palindrome

public class Palindrome {


public boolean isPalindrome(ListNode head) {
return false;
}

static boolean isEqual(ListNode firstNode, ListNode secondNode){
while (firstNode != null && secondNode != null){
if (firstNode.data != secondNode.data){
return false;
}
firstNode = firstNode.next;
secondNode = secondNode.next;
}
return firstNode == null && secondNode == null;
}

public ListNode reverseAndClone(ListNode node){

}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package advance.crackingCodingInterview.linkedList.palindromes;public class PalindromeStack {
}
2 changes: 2 additions & 0 deletions src/advance/linkedlist/LFUCache.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package advance.linkedlist;public class LFUCache {
}

0 comments on commit 2a72d23

Please sign in to comment.