-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0c23ea
commit 0f7cc15
Showing
4 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Time complexity - O(n) | ||
Space complexity - O(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Time complexity - O(n * logn) | ||
Space complexity - O(n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |