-
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
87ce6e7
commit 32c9e23
Showing
4 changed files
with
77 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,50 @@ | ||
//{ Driver Code Starts | ||
// Initial Template for Java | ||
|
||
import java.io.*; | ||
import java.lang.*; | ||
import java.util.*; | ||
|
||
class GFG { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
int T = Integer.parseInt(br.readLine().trim()); | ||
while (T-- > 0) { | ||
String[] s = br.readLine().trim().split(" "); | ||
int V = Integer.parseInt(s[0]); | ||
int E = Integer.parseInt(s[1]); | ||
ArrayList<ArrayList<Integer>> adj = new ArrayList<>(); | ||
for (int i = 0; i < V; i++) adj.add(i, new ArrayList<Integer>()); | ||
for (int i = 0; i < E; i++) { | ||
String[] S = br.readLine().trim().split(" "); | ||
int u = Integer.parseInt(S[0]); | ||
int v = Integer.parseInt(S[1]); | ||
adj.get(u).add(v); | ||
adj.get(v).add(u); | ||
} | ||
Solution obj = new Solution(); | ||
boolean ans = obj.isEularCircuitExist(V, adj); | ||
if (ans) | ||
System.out.println("1"); | ||
else | ||
System.out.println("0"); | ||
} | ||
} | ||
} | ||
// } Driver Code Ends | ||
|
||
|
||
// User function Template for Java | ||
|
||
class Solution | ||
{ | ||
public boolean isEularCircuitExist(int v, ArrayList<ArrayList<Integer>> adj) | ||
{ | ||
// Code here | ||
for(ArrayList<Integer> ad : adj) | ||
if(ad.size()%2!=0) | ||
return false; | ||
|
||
return true; | ||
} | ||
} |
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(v) | ||
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) | ||
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,23 @@ | ||
class Solution | ||
{ | ||
public long countSubarrays(int[] nums, int k) | ||
{ | ||
int maxNum = Arrays.stream(nums).max().getAsInt(); | ||
long ans = 0; | ||
int count = 0; | ||
|
||
for (int l = 0, r = 0; r < nums.length; ++r) | ||
{ | ||
if (nums[r] == maxNum) | ||
++count; | ||
|
||
while (count == k) | ||
if (nums[l++] == maxNum) | ||
--count; | ||
|
||
ans += l; | ||
} | ||
|
||
return ans; | ||
} | ||
} |