Skip to content

Commit

Permalink
Added codes for 29 April
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed Apr 29, 2024
1 parent eeec2c3 commit 481a4f4
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
101 changes: 101 additions & 0 deletions GeeksForGeeks/April/29-4-24/GFG.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
//{ Driver Code Starts
import java.util.*;
class Node
{
Node next;
int data;

Node(int d)
{
data = d;
next = null;
}
}
class Delete_Kth_Node
{
Node head;
Node tail;

void addToTheLast(Node node){
if(head == null){
head = node;
tail = node;
}
else
{
tail.next = node;
tail = tail.next ;
}
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
while(t>0)
{
int n = sc.nextInt();
Delete_Kth_Node list = new Delete_Kth_Node();
//int n=Integer.parseInt(br.readLine());
int a1=sc.nextInt();
Node head= new Node(a1);
list.addToTheLast(head);
for (int i = 1; i < n; i++)
{
int a = sc.nextInt();
list.addToTheLast(new Node(a));
}
int k = sc.nextInt();
//System.out.println(list.head.data+" "+ k);
list.head = new Solution().delete(list.head,k);
Node temp = list.head;
while(temp!=null)
{
System.out.print(temp.data+ " ");
temp = temp.next;
}
System.out.println();
t--;
}
}
}
// } Driver Code Ends


/* Link list Node
class Node
{
Node next;
int data;
Node(int d)
{
data = d;
next = null;
}
}*/
class Solution
{
/*You are required to complete this method*/
Node delete(Node head, int k)
{
// Your code here
Node prev = new Node(-1);
Node temp = prev;
prev.next = head;
int cnt = 1;
while(temp.next!=null)
{
if(cnt==k)
{
temp.next = temp.next.next;
cnt = 0;
}
else
{
temp = temp.next;
}
cnt++;
}

return prev.next;
}
}
2 changes: 2 additions & 0 deletions GeeksForGeeks/April/29-4-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n)
Space complexity - O(1)
2 changes: 2 additions & 0 deletions LeetCode/April/29-4-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n)
Space complexity - O(1)
8 changes: 8 additions & 0 deletions LeetCode/April/29-4-24/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Solution
{
public int minOperations(int[] nums, int k)
{
int xors = Arrays.stream(nums).reduce((a, b) -> a ^ b).getAsInt();
return Integer.bitCount(k ^ xors);
}
}

0 comments on commit 481a4f4

Please sign in to comment.