Skip to content

Commit

Permalink
Added codes for 29 March
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanmay-312 committed Mar 29, 2024
1 parent 87ce6e7 commit 32c9e23
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
50 changes: 50 additions & 0 deletions GeeksForGeeks/March/29-3-24/GFG.java
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;
}
}
2 changes: 2 additions & 0 deletions GeeksForGeeks/March/29-3-24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time complexity - O(v)
Space complexity - O(1)
2 changes: 2 additions & 0 deletions LeetCode/March/29-3-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)
23 changes: 23 additions & 0 deletions LeetCode/March/29-3-24/Solution.java
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;
}
}

0 comments on commit 32c9e23

Please sign in to comment.