Skip to content

Commit

Permalink
Added codes for 10 April
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed Apr 10, 2024
1 parent d0c23ea commit 0f7cc15
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
44 changes: 44 additions & 0 deletions GeeksForGeeks/April/10-4-24/GFG.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//{ Driver Code Starts
//Initial Template for Java
import java.io.*;
import java.util.*;

class GFG
{
public static void main(String args[])throws IOException
{
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(read.readLine());
while(t-- > 0)
{
int N = Integer.parseInt(read.readLine());
String input_line[] = read.readLine().trim().split("\\s+");
int arr[]= new int[N];
for(int i = 0; i < N; i++)
arr[i] = Integer.parseInt(input_line[i]);

Solution ob = new Solution();
System.out.println(ob.findSingle(N, arr));
}
}
}

// } Driver Code Ends


//User function Template for Java

class Solution
{
static int findSingle(int n, int arr[])
{
// code here
int x = 0;
for (int i = 0; i < n; i++)
{
x = x ^ arr[i];
}

return x;
}
}
2 changes: 2 additions & 0 deletions GeeksForGeeks/April/10-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/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(n * logn)
Space complexity - O(n)
24 changes: 24 additions & 0 deletions LeetCode/April/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Solution
{
public int[] deckRevealedIncreasing(int[] deck)
{
int n = deck.length;

Arrays.sort(deck);

Deque<Integer> dq = new ArrayDeque<>();
dq.addFirst(deck[n - 1]);

for (int i = n - 2; i >= 0; --i)
{
dq.addFirst(dq.getLast());
dq.pollLast();
dq.addFirst(deck[i]);
}

for (int i = 0; i < n; ++i)
deck[i] = dq.pollFirst();

return deck;
}
}

0 comments on commit 0f7cc15

Please sign in to comment.